If GetVelocity() = 0,0,0 at spawning how do I make an actor move in its facing direction?

Hi.

In the Unreal API it describes GetActorForwardVector as “Get the forward (X) vector (length 1.0) from this Actor, in world space”.

Practically, just wasn’t sure what this means. The code below just moves the actor directly north up the screen irrespective of the way its facing.

void AEnemyShip::Tick(float DeltaTime)

{

Super::Tick(DeltaTime);

UE_LOG(LogTemp, Warning, TEXT("actor location is  %s"), *GetActorLocation().ToString());

UE_LOG(LogTemp, Warning, TEXT("actor velocity sis  %s"), *GetVelocity().ToString());


FVector newVector = GetActorLocation() + currentForwardVector + (.00001 * DeltaTime);

SetActorLocation(newVector);

}

If my Pawn is spawned at position (0, 0, 0) in the world and is rotated to face in the North-East direction (45 degrees) what will be the result of GetActorForwardVector? Is it just the X location?

I guess my next question is if I wish to move the Pawn in the direction its facing (45 degress from north) what do I use? Do I need to find the dot product?
Because at spawning GeVelocity is 0,0,0 so not sure how best to handle this.

Thanks.

A forward vector is a vector with a length of 1 that defines the direction of the pawn’s forward. I don’t have the capacity to put an explanation in words, but Mathew Wadstein has a great video on this. If you look at the top right of his viewport you can see the value of the player’s forward vector. Take a look at how he moves the player and how the vector correlates to that movement. I suggest you also look at his other videos as he has a TON of videos covering many different little topics.

If you wanted to move a pawn by one meter in the forward direction, you first have to find the movement vector that defines how the player will move in three dimensions (move one unit forward, move .5 unit forward and .5 unit left, etc). Then, you add the pawn’s current location with the movement vector.



// Psuedo-code

// Pawn will be able to move only one meter in any direction
DistancePerTick = 1;

// How far we can move multiplied by what direction we move in gives us direction and length of our movement
MovementVector = DistancePerTick * PawnForward;

// To get our new location, we take the current location and add the distance+direction we are going to travel
NewPawnLocation = CurrentPawnLocation + MovementVector;


Also, GetVelocity returns the pawn’s current velocity, not the velocity the pawn is able to move. We set the speed the pawn is able to move in one frame with DistancePerTick.

Every object that can be rendered has a transform.

A transform has a Translation(or position) a rotation(or orientation) and a Scale.

The orientation is defined with the x-axis being forward and z-axis is up, and y axis is to the right.

So GetActorForwardVector will return the x-axis of the orientation in world space.

Thanks. Yeah…I just figured out the bit that I’ve been missing…basically the issue I have had in understanding this is that it is all with reference (I think) to the pivot point of your static mesh. Each mesh has that little X, Y, Z arrow direction marker associated with it and GetActorForwardVector is just the vector direction of “X”. So if you have an airplane as your static mesh if the little X,Y,Z marker has the red “X” arrow in the direction of the propellor then GetActorForwardVector will go in the direction of the X ie the way the propellor is facing. So it doesn’t matter which way the plane is rotated, because the X is “baked” into the direction of the propellor. Cheers.