Strange rotation issue when moving right

Hello, I’ve closely followed the tutorial but I’m getting some strange behavior between rotating and strafing when I hit Play. If I press play and then use the mouse to rotate the character so that the mesh is facing 90 degrees counter-clockwise to where it started, and then if I press the forward key, the character strafes to the left. If I rotate the character another 90 degrees counter-clockwise (so it’s facing the opposite direction to when it started the level) and press the forward key, the character moves backwards in relation to the direction its facing.

Basically, when the mesh looks like it’s rotated 90 degrees, the controls act like the movement component has rotated 180 degrees, when the mesh looks like it’s rotated 180 degrees, the controls act like the movement component has rotated 360 degrees.

I’ve tried changing things like “UseControllerYaw” in the Pawn settings, “Rotation Rate” in the Character Movement Component settings, and “Input Yaw Scale” in the PlayerController settings, but none of those seem to be the issue. I feel like it’s a problem that was brought up in one of the older tutorials, but I can’t work out what’s going on.

I’ve found the problem, instead of:

void AShooterCharacter::MoveRight(float MovementInput) 
{
	AddMovementInput(GetActorRightVector() * MovementInput, true);
}

I had:

void AShooterCharacter::MoveRight(float MovementInput) 
{
	AddActorLocalOffset(GetActorRightVector() * MovementInput, true);
}

I’ve tried looking both APawn::AddMovementInput and AActor::AddActorLocalOffset, but I’m still confused by what was happening. Why did rotating the actor 90 degrees make the movement component act like it had been rotated 180?

Edit: I’ve also had a look at AddLocalOffset() in SceneComponent.cpp but I’m still not sure I understand what’s happening.

I would suggest you log out the value of GetActorRightVector.

P.S. AddMovementInput doesn’t take a bool as the second argument, it’s a float for the scale but you’re already multiplying that in the first argument so you don’t need to pass anything extra.

1 Like

Ok, that was indeed really helpful (I’m glad I spent some time drawing the Z-up, left-handed co-ordinate all over my hands and memorising it). So as far as I understand now, GetActorRightVector returns the right vector in world space, but I was applying it locally with AddActorLocalOffset?

Presumably AddMovementInput applies the FVector that’s passed into it in world space?

Correct.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms