Unwanted rotation on physics based movement system

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?

1 Like

Hey guys,

been trying to fix this for the past week here and there with little to no success.

For debugging, I’ve added the following debugging code:

	GEngine->AddOnScreenDebugMessage(-1, 0.005f, FColor::Red,
		FString::Printf(TEXT("Forward Vector: %s \n"
		"Value.Y: %f \n"
		"MovementForce: %f \n"
		"Direction: %s"),
		*PlayerCollider->GetForwardVector().ToString(),
		Value.Y,
		MovementForce,
		*Direction.ToString()));

With the output of:
image

whenever I press the W key and disabling the rotation. I’ve noticed that the Y-value keeps changing even though it actually shouldn’t since I am only pressing W.

Could someone help me figure out what’s the problem with the adding of the force to the pawn, because I can’t think of anything else.

EDIT: Quickly changing the AddImpulse/AddForce to SetPhysicsLinearVelocity did not change the outcome. The Y-Value keeps changing. Also ticking the IgnoreRadialForce did not fix the issue neither.

1 Like

(post deleted by author)

1 Like

Hey,

I tried to simplify the problem into the most barebones as I could in blueprints.

Here’s the following code:

The above is creating the same problem as before. As in generating radial force and turning the player even though no such function or method has been called.

Ticking the following bools do not affect the outcome:
kuva

Is it a bug with the UE physics engine? I’m using UE 5.4.4

1 Like
  • create a new actor in BP, with just a collider (capsule?), have it block and simulate physics - what result do you get as you Add Force / Impulse along the fwd as above?
  • in your current actor, add a debug arrow (or draw debug arrow / print fwd vector) - does it make sense when you do?

What I’m getting at - chances are the fwd is not the vector you think it is, something else that we cannot see here affects it.

Besides that, could you show / explain what other components are there in the hierarchy of the misbehaving character / pawn? Is the collider the root component?


Not that it’s much direct help, this moves a pawn with a simple collider straight as an arrow:

At least in 5.3.3

1 Like

Here’s what I’ve gathered as I tried to test my hypothesis about it being a physics engine issue in 5.4.4.

  1. I did as you said and the newly created blueprint pawn with only the capsule collider and the same blueprint calls. The issue still presists. Also about drawing the forward vector you can refer to my previous post about it:

Hey guys,

been trying to fix this for the past week here and there with little to no success.

For debugging, I’ve added the following debugging code:

	GEngine->AddOnScreenDebugMessage(-1, 0.005f, FColor::Red,
		FString::Printf(TEXT("Forward Vector: %s \n"
		"Value.Y: %f \n"
		"MovementForce: %f \n"
		"Direction: %s"),
		*PlayerCollider->GetForwardVector().ToString(),
		Value.Y,
		MovementForce,
		*Direction.ToString()));

With the output of:
image

whenever I press the W key and disabling the rotation. I’ve noticed that the Y-value keeps changing even though it actually shouldn’t since I am only pressing W.

I’ve noticed that the forward vector was rotating as momentum was added.

  1. I also did the same with the UE 5.3.2 version. As in only blueprints. No issues. It goes forward without any additional force to the rotation. It seems that its an issue with UE 5.4.4

I also did the same with the UE 5.3.2 version. As in only blueprints. No issues. It goes forward without any additional force to the rotation. It seems that its an issue with UE 5.4.4

Ouch then. You’ve been at it for 2 weeks now :expressionless:

Yeah, it was breaking me for so long as I did not find any posts or any mention on others having the same issue as I was. But now that I’ve realised what cause of the problem was, I’m even more broken now. :frowning:

How about a non-capsule collider? Pushing a physics box turns it to the side, too?!

The one on the left is UE 5.4.4 (latest at the time of writing)
The one on the right is UE 5.3.2

UE 5.4.4 has some weird physics bug that makes the player pawn to rotate. If you’re using 5.4.4, downgrade or wait for a new update.

I actually did, mainly because of the Physics Control component not working correctly. I’ve just had a quick scrub through the bug db and, while I cannot find this specific issue, there are some truly worrying entries:

This has worked for the last 12 years, who knows what else might be broken.

1 Like

Yes, even the box collider wants to rotate on its own.

1 Like

I’ve even had some issues with the basic AddMovementInput() method with the character .cpp files. Now I don’t know If it was a me issue or the engine version’s fault. But at the moment I do suspect the latter option.