# Move pawn along forward/right vectors

**URL:** <https://forums.unrealengine.com/t/move-pawn-along-forward-right-vectors/411215>\
**Category:** Character & Animation\
**Tags:** forward-vector, unreal-engine, CPP, question, vectors\
**Created:** [December 2, 2017, 9:01pm UTC](https://forums.unrealengine.com/t/move-pawn-along-forward-right-vectors/411215 "2017-12-02T21:01:44Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![MartyBro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MartyBro](https://forums.unrealengine.com/u/MartyBro)\
**Post date:** [December 2, 2017, 9:01pm UTC](https://forums.unrealengine.com/t/move-pawn-along-forward-right-vectors/411215/1 "2017-12-02T21:01:44Z")

</div>

I have created a pawn that moves along the x and y axis, and rotates left and right. However, when I rotate, the pawn still moves along the original x and y axis, so it doesn’t look right when it moves after rotating. How would I use the pawns forward and right vectors to correct the movement so that the pawn still moves correctly?

---

<div class="post-metadata">

**Author:** ![Firefly74](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Firefly74](https://forums.unrealengine.com/u/Firefly74)\
**Post date:** [December 3, 2017, 7:39am UTC](https://forums.unrealengine.com/t/move-pawn-along-forward-right-vectors/411215/2 "2017-12-03T07:39:44Z")

</div>

Hi ! Looks like a duplicated question, check the answer here :

> **[\[Noob question\] Moving a pawn relative to the world space](https://forums.unrealengine.com/questions/723716/noob-question-moving-a-pawn-relative-to-the-world.html)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![MartyBro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MartyBro](https://forums.unrealengine.com/u/MartyBro)\
**Post date:** [December 3, 2017, 1:47pm UTC](https://forums.unrealengine.com/t/move-pawn-along-forward-right-vectors/411215/3 "2017-12-03T13:47:30Z")

</div>

Unfortunately, when I tried to implement this, it didn’t work. I don’t know why, but apparently this approach doesn’t work for me. Thank you though.

---

<div class="post-metadata">

**Author:** ![Firefly74](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Firefly74](https://forums.unrealengine.com/u/Firefly74)\
**Post date:** [December 3, 2017, 5:38pm UTC](https://forums.unrealengine.com/t/move-pawn-along-forward-right-vectors/411215/4 "2017-12-03T17:38:47Z")

</div>

Then maybe your rotation code is doing something wrong, do you rotate controler ? Pawn ? Camera ?

---

<div class="post-metadata">

**Author:** ![MartyBro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MartyBro](https://forums.unrealengine.com/u/MartyBro)\
**Post date:** [December 3, 2017, 5:41pm UTC](https://forums.unrealengine.com/t/move-pawn-along-forward-right-vectors/411215/5 "2017-12-03T17:41:07Z")

</div>

I’m rotating a pawn. I have a variable which gets the pawns rotation and then adds/subtracts depending on the buttons pressed. However, the vectors do not rotate and I cannot figure out how to get them to rotate.

---

<div class="post-metadata">

**Author:** ![Firefly74](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Firefly74](https://forums.unrealengine.com/u/Firefly74)\
**Post date:** [December 3, 2017, 6:25pm UTC](https://forums.unrealengine.com/t/move-pawn-along-forward-right-vectors/411215/6 "2017-12-03T18:25:14Z")

</div>

Could you share:

-your moving code + name of method + class it is in

-your turning code + name of method+ class it is in

---

<div class="post-metadata">

**Author:** ![MartyBro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MartyBro](https://forums.unrealengine.com/u/MartyBro)\
**Post date:** [December 3, 2017, 6:29pm UTC](https://forums.unrealengine.com/t/move-pawn-along-forward-right-vectors/411215/7 "2017-12-03T18:29:55Z")

</div>

void ADuck::Tick(float DeltaTime)  
{  
Super::Tick(DeltaTime);

```
// Turning left and right
FRotator TurningValue = GetActorRotation();
if (bTurningLeft)
{
	TurningValue.Yaw -= 1;
}
if (bTurningRight)
{
	TurningValue.Yaw += 1;
}
SetActorRotation(TurningValue);

// Move in all directions, but restrict movement to set distance so duck stays on water
if (!Velocity.IsZero())
{
	FVector NewDuckLocation = GetActorLocation() + (Velocity * DeltaTime);
	NewDuckLocation.X = FMath::Clamp(int(NewDuckLocation.X), 150, 665);
	NewDuckLocation.Y = FMath::Clamp(int(NewDuckLocation.Y), 120, 675);
	SetActorLocation(NewDuckLocation);
}

```

}

void ADuck::MoveForwardBackward(float AxisValue)  
{

```
// Move along the x-axis using controls set in the project settings
Velocity.X = FMath::Clamp(AxisValue, -1.0f, 1.0f) * 500.0f;

```

}

void ADuck::MoveLeftRight(float AxisValue)  
{  
// Move along the y-axis using controls set in the project settings  
Velocity.Y = FMath::Clamp(AxisValue, -1.0f, 1.0f) \* 500.0f;  
}

void ADuck::LeftTurn()  
{  
bTurningLeft = true;  
}

void ADuck::LeftStop()  
{  
bTurningLeft = false;  
}

void ADuck::RightTurn()  
{  
bTurningRight = true;  
}

void ADuck::RightStop()  
{  
bTurningRight = false;  
}

```
// Input functions for movement, turning 
void MoveForwardBackward(float AxisValue);
void MoveLeftRight(float AxisValue);
void LeftTurn();
void LeftStop();
void RightTurn();
void RightStop();

// Input variables for movement, turning
FVector Velocity;
bool bTurningLeft;
bool bTurningRight;

```

This is all the code to do with turning and moving at the moment.

---

<div class="post-metadata">

**Author:** ![Firefly74](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Firefly74](https://forums.unrealengine.com/u/Firefly74)\
**Post date:** [December 5, 2017, 1:46pm UTC](https://forums.unrealengine.com/t/move-pawn-along-forward-right-vectors/411215/8 "2017-12-05T13:46:47Z")

</div>

so using

```
 FVector NewDuckLocation = GetActorLocation() + (TurningValue.RotateVector(Velocity) * DeltaTime);

```

doesn’t work ?  
remove your binary folder and rebuild to be sure to have up to date binaries

---

<div class="post-metadata">

**Author:** ![MartyBro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MartyBro](https://forums.unrealengine.com/u/MartyBro)\
**Post date:** [December 6, 2017, 11:05am UTC](https://forums.unrealengine.com/t/move-pawn-along-forward-right-vectors/411215/9 "2017-12-06T11:05:00Z")

</div>

This works for moving along the y axis, or left and right, but when I attempt to move forward and backward along the x axis, I find that I can only move forward no matter which button I press, and if I try to go forward I end up going down and through the floor, and if I go backwards I end up going up and floating above the floor. I will try using clamp on the z axis of the duck, but I’m still not sure what to do about the only moving forwards thing.

---

<div class="post-metadata">

**Author:** ![MartyBro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MartyBro](https://forums.unrealengine.com/u/MartyBro)\
**Post date:** [December 6, 2017, 11:08am UTC](https://forums.unrealengine.com/t/move-pawn-along-forward-right-vectors/411215/10 "2017-12-06T11:08:42Z")

</div>

And by clamping the z axis, I now cannot move forward and backward at all

---

<div class="post-metadata">

**Author:** ![Firefly74](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Firefly74](https://forums.unrealengine.com/u/Firefly74)\
**Post date:** [December 6, 2017, 11:23am UTC](https://forums.unrealengine.com/t/move-pawn-along-forward-right-vectors/411215/11 "2017-12-06T11:23:16Z")

</div>

Then maybe try :

```
FVector NewDuckLocation = GetActorLocation() + (FRotator(0, TurningValue.Yaw, 0).RotateVector(Velocity) * DeltaTime);
```

---

<div class="post-metadata">

**Author:** ![MartyBro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MartyBro](https://forums.unrealengine.com/u/MartyBro)\
**Post date:** [December 6, 2017, 11:30am UTC](https://forums.unrealengine.com/t/move-pawn-along-forward-right-vectors/411215/12 "2017-12-06T11:30:34Z")

</div>

I fixed it by changing the direction of movement from the x axis to the z axis, thank you for pointing me in the right direction
