Which method is right for getting forward vector of an actor.

Hi,
I am trying to get the forward vector of an actor. If the actor is rotated in world space, I am not getting the forward vector of the actor.
I am not sure if I am doing it the right way. Please checkout the code:


	
USceneComponent* SceneComp = Cast<USceneComponent>(GetComponentByClass(USceneComponent::StaticClass()));
const FRotator Rotation = SceneComp->GetComponentRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
// get forward vector
const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
AddActorLocalOffset(Direction * Speed* DeltaTime, true);


Reply,

Just call GetForwardVector() on the scene component? USceneComponent::GetForwardVector | Unreal Engine Documentation

There’s a function as part of actor class called GetActorForwardVector(); - which just calls ‘GetForwardVector()’ on the root component.

I had tried the GetForwardVector() and the GetActorForwardVector() method first, and it was same giving error. After your replies I realized that I was applying the wrong offset method. I needed to use the AddActorWorldOffset() method instead of AddActorLocalOffset(). Silly mistake but I wasted a day on it, :smiley:

bangs head!

It is also possible that the object spawns directly in front of you, but only rotates about the z-axis and not three-dimensional??

Got it with break rotator and make rotator!!!