# Why isn't VInterpTo(AActor-\>GetForwardVector()) moving forward?

**URL:** <https://forums.unrealengine.com/t/why-isnt-vinterpto-aactor-getforwardvector-moving-forward/325210>\
**Category:** Editor Scripting\
**Tags:** fvector, interpolation, unreal-engine, question, CPP\
**Created:** [July 14, 2015, 3:07pm UTC](https://forums.unrealengine.com/t/why-isnt-vinterpto-aactor-getforwardvector-moving-forward/325210 "2015-07-14T15:07:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![HInoue](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HInoue](https://forums.unrealengine.com/u/HInoue)\
**Post date:** [July 14, 2015, 3:07pm UTC](https://forums.unrealengine.com/t/why-isnt-vinterpto-aactor-getforwardvector-moving-forward/325210/1 "2015-07-14T15:07:08Z")

</div>

I’m trying to write a function that will VInterpTo() every tick to move the player an arbitrary distance in a given direction, in this case in the direction he’s facing:

```
void UMovementNotifyState::NotifyBegin(USkeletalMeshComponent * MeshComp, UAnimSequenceBase * Animation, float TotalDuration){
	myActor = Cast<AActor>(MeshComp->GetOwner()); //Cache a reference to the ACharacter to be moved, as an actor
	myCharacter = Cast<ACharacter>(MeshComp->GetOwner());
	if (myCharacter != nullptr && myActor != nullptr){ //Sanity check to prevent Persona crashing
		startLocation = myCharacter->GetActorLocation(); //Set the starting node to our current position
		endLocation = myCharacter->GetActorForwardVector()*moveDistance; //Set the ending node to a position float moveDistance unreal units forward of our current facing
	}
}

void UMovementNotifyState::NotifyTick(USkeletalMeshComponent * MeshComp, UAnimSequenceBase * Animation, float FrameDeltaTime){
	if (myCharacter != nullptr && myActor != nullptr){//Sanity check		
				float Alpha = 5;				
				destinationLocation = FMath::VInterpTo(startLocation, endLocation, FrameDeltaTime, Alpha);
				myCharacter->SetActorLocation(destinationLocation,true);
	}
}

```

This compiles fine, but the movement it creates is seemingly random: movement direction is independent of the character’s facing, and seems to either push him away in a random direction, or suck him towards the world origin. The most obvious explanation in my mind is that the vector math is wrong, and endLocation doesn’t point to a position n units in front of the character like I think it does, but I’m really lost when it comes to how to fix it.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_33e74471](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_33e74471](https://forums.unrealengine.com/u/anonymous_user_33e74471)\
**Post date:** [July 14, 2015, 3:12pm UTC](https://forums.unrealengine.com/t/why-isnt-vinterpto-aactor-getforwardvector-moving-forward/325210/2 "2015-07-14T15:12:41Z")

</div>

I am guessing that you need to add startLocation to your current endLocation, as your endLocation will always be around 0 since GetActorForwardVector is a unit vector pointing forward, not a position in space in front of your character. He’s probably always moving to a location kind of by (0,0,0).

Edit:  
Like this.

![50172-position.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/9/4/a94b63e7b42c66689d934ec7ee28e44eb41a0b69.png)

---

<div class="post-metadata">

**Author:** ![HInoue](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HInoue](https://forums.unrealengine.com/u/HInoue)\
**Post date:** [July 14, 2015, 4:27pm UTC](https://forums.unrealengine.com/t/why-isnt-vinterpto-aactor-getforwardvector-moving-forward/325210/3 "2015-07-14T16:27:29Z")

</div>

Hmm, I kind of see what you mean, I was definitely stuck thinking of the vector as a coordinate triple, not a unit vector. You mean add the two together when I first calculate endLocation like this, not inside the final interpolation, right?

```
endLocation = (myCharacter->GetActorForwardVector() + startLocation) *moveDistance;

```

That’s the only thing I changed from the original post, but he still seems to get sucked towards the origin. I made a handy-dandy video showing this in action- the notify is on his jump animation, so every time it jumps the vinterpto logic runs: [Imgur: The magic of the Internet](http://imgur.com/YCdxqmD)

Since he’s still getting sucked into the same rough area, I’m convinced trying to grab the forward vector is the culprit. I tried a slightly different approach, and added rotation in while I was at it:

```
	FVector movementVector = myActor->GetActorForwardVector()*moveDistance; //Set the ending node to a position float moveDistance unreal units forward of our current facing
	movementVector = movementVector.RotateAngleAxis(moveDirection, FVector(0, 0, 1));
	endLocation = movementVector;

```

The rotation part works fine, but it still ends up getting sucked into the same corner whenever it fires.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_33e74471](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_33e74471](https://forums.unrealengine.com/u/anonymous_user_33e74471)\
**Post date:** [July 14, 2015, 5:10pm UTC](https://forums.unrealengine.com/t/why-isnt-vinterpto-aactor-getforwardvector-moving-forward/325210/4 "2015-07-14T17:10:14Z")

</div>

> I was definitely stuck thinking of the vector as a coordinate triple, not a unit vector.

It is kind of both. The problem you’re having is that the forward vector is just a directional vector. It isn’t a point in space in front of the player. It’s the direction the player is facing from the origin. It’s a coordinate triple relative to the player’s location, not relative to the world.

> You mean add the two together when I first calculate endLocation like this, not inside the final interpolation, right?

Like this:

```
endLocation = startLocation + (myCharacter->GetActorForwardVector() *moveDistance);

```

Your new one will move to a really odd location depending on where the current start location is. For example if you are at (1,1,1) facing down the X axis with forward vector (1, 0, 0) and you want to move 2 units that way, you want to end up at (3,1,1) not (4,2,2).

---

<div class="post-metadata">

**Author:** ![HInoue](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HInoue](https://forums.unrealengine.com/u/HInoue)\
**Post date:** [July 14, 2015, 11:57pm UTC](https://forums.unrealengine.com/t/why-isnt-vinterpto-aactor-getforwardvector-moving-forward/325210/5 "2015-07-14T23:57:31Z")

</div>

The sound you don’t hear is a boatload of celebratory cymbals and fireworks going off, because this finally works- thank you so much for your patient explanation and the illustration! Vector math scares the heck out of me every time I try to make it work 🙂
