Hi there,
I have a odd problem with unwanted rotation as the title says. I’m using the a PlayerController class to manage the user input and send that information to the player character through delegates using the new EnhancedInput system.
In short whenever I add rotation to the direction of the forward vector of the player, it starts to rotate toward the right with no other input than the W key. Even when disabling PlayerCollider->GetRightVector() * Value.X * MovementForce; it still rotates.
I’ve thought about drag being the issue, but I cannot find anything related to that in the physics settings.
PlayerController.cpp
void ACPPlayerControllerBase::PlayerMove(const FInputActionValue& InputActionValue)
{
// Value is a Vector2D
const FVector2D MovementVector = InputActionValue.Get<FVector2D>();
// Add movement to the player's character pawn
if(PlayerPawn)
PlayerMoveDelegate.Execute(MovementVector, MovementForce);
}
PlayerCharacter.cpp
void APlayerPawn::Move(const FVector2D Value, const float MovementForce) const
{
const FVector Direction =
PlayerCollider->GetForwardVector() * Value.Y * MovementForce +
PlayerCollider->GetRightVector() * Value.X * MovementForce;
GEngine->AddOnScreenDebugMessage(-1, 0.005f, FColor::Red, FString::Printf(TEXT("Forward Vector: %s"), *PlayerCollider->GetForwardVector().ToString()));
if (PlayerCollider->GetComponentVelocity().Length() < 500.f)
PlayerCollider->AddForce(Direction);
}
I can’t for the life of me understand why it rotates and keeps rotating for a while after adding force. Any help would be appreciated. Thanks in advance.
TL;DR: Whenever I add force to the forward vector of the player, it starts rotating to the side even when mouse input is disabled.
EDIT: The player character also keeps spinning after stopped giving input. It seems that the force somehow also is being added to the rotation, even though it shouldn’t be?
EDIT 2: I’ve tried setting the angular damping to 25, 50, 500, 5000 and even 50000! Everytime it veers off the straight path.
EDIT 3: Even tried changing AddForce to AddImpulse with no change. Would it be something to do with the ForwardVector?