I have a weird problem that needs an equally weird solution. Basically, I am trying to have my player land on a platform while retaining 'overlap all' for the player and the platform (Paper2D, but shouldn't matter).
Shouldn't this counteract the Z gravity and hold the player in place while it runs on the tick?
I asked a similar question on the answer hub: https://answers.unrealengine.com/que...-question.html
Code:
CapsuleComponent->AddForceAtLocation(FVector(0, 0, GetVelocity().Z * -1), GetActorLocation());
I asked a similar question on the answer hub: https://answers.unrealengine.com/que...-question.html
Code:
void ATestPlatCharacter::Tick(float DeltaSeconds){ Super::Tick(DeltaSeconds); GEngine->ClearOnScreenDebugMessages(); FVector coords = GetActorLocation(); x = coords.X; z = coords.Z; depth = coords.Y; if (place_meeting<APlatformParent>(x,z - 1)) { free = 0; } else { free = 1; } if (free == 0) { /* Does not work. */ //CapsuleComponent->SetEnableGravity(false); //CapsuleComponent->AddImpulseAtLocation(FVector(0, 0, GetVelocity().Z * -1), GetActorLocation()); //CapsuleComponent->AddForceAtLocation(FVector(0, 0, GetVelocity().Z * -1), GetActorLocation()); //CapsuleComponent->ComponentVelocity = FVector(0, 0, 0); //CapsuleComponent->SetEnableGravity(false); //bSimGravityDisabled = true; /* Kinda works but doesnt'. */ //CharacterMovement->Velocity = FVector(0, 0, 0); //CharacterMovement->Velocity.Z = 0; /* This tries to work, but then there is no friction. Perhaps compensate? */ //CharacterMovement->GravityScale = 0.0f; //CharacterMovement->Velocity.Z = 0; CapsuleComponent->AddForceAtLocation(FVector(0, 0, GetVelocity().Z * -1), GetActorLocation()); } else { //The character is not on the ground. } GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, FString::SanitizeFloat(GetVelocity().Z)); //GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, FString("free = ") + FString::FromInt(free)); }
Comment