[Noob question] Moving a pawn relative to the world space

Hi, I’m really struggling to get this to work. Would really appreciate a nudge in the right direction.

I have an actor, which can move up/down and left/right. When this actor is rotated 90deg clockwise, up is becoming left.

I can’t get it to stay moving forward, based on it’s current rotation (amazing diagram below).

219585-untitled.jpg

My current implimentation is as follows:

void AZumoPlayer::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	PlayerPawnInput.Sanitize();

	//Move the Player
	FVector DesiredMovementDirection = FVector(PlayerPawnInput.MovementInput.Y, PlayerPawnInput.MovementInput.X, 0.0f);	
	FVector CurrentPos = GetActorLocation();
	CurrentPos.X += DesiredMovementDirection.X * MoveSpeed * DeltaTime;
	CurrentPos.Y += DesiredMovementDirection.Y * MoveSpeed * DeltaTime;
	SetActorLocation(CurrentPos);
}

Any help is appreciated. I’m new to ue4 c++ and really having a lot of trouble working this one out.

i would rotate "DesiredMovementDirection "

FVector DesiredMovementDirection = FVector(PlayerPawnInput.MovementInput.Y, PlayerPawnInput.MovementInput.X, 0.0f);    
DesiredMovementDirection =GetActorRotation().RotateVector(DesiredMovementDirection)

that should work ( you might have to swap your X and Y though )

1 Like

Dude, I forgot to reply when I implemented this, but this works flawlessly. Thank you so much.

I would’ve thought you could add movement in relation to the pawn using AddActorLocalLocation() [or something along those lines] but this didn’t seem to work when I tried it.

Thank you! Great answer, this just saved me another 2 days of testing!