# Can't get actor to face direction properly

**URL:** <https://forums.unrealengine.com/t/cant-get-actor-to-face-direction-properly/467051>\
**Category:** Character & Animation\
**Tags:** actor-rotation, player-rotation, unreal-engine, question\
**Created:** [June 21, 2020, 9:29am UTC](https://forums.unrealengine.com/t/cant-get-actor-to-face-direction-properly/467051 "2020-06-21T09:29:32Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Strid\_By\_Swedork](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Strid\_By\_Swedork](https://forums.unrealengine.com/u/Strid_By_Swedork)\
**Post date:** [June 21, 2020, 9:29am UTC](https://forums.unrealengine.com/t/cant-get-actor-to-face-direction-properly/467051/1 "2020-06-21T09:29:32Z")

</div>

Hello, total noob here!

I’m trying to get my actor to instantly face the direction of the vector of witch it’s moving.

But i cant seem to instantly rotate the actor the way i want to. Instead of just facing the right direction, it slowly rotates in the direction i want.

[Video of the problem here](https://youtu.be/lA_ynTsXV1k)

My code snippet looks like this:

```
	FQuat quat = GetActorLocation().ToOrientationQuat();
	PlayerActorComponent->SetWorldRotation(quat);

```

If anyone knowes how to solve this, it would be great.

---

<div class="post-metadata">

**Author:** ![EvilCleric](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@EvilCleric](https://forums.unrealengine.com/u/EvilCleric)\
**Post date:** [June 21, 2020, 9:37am UTC](https://forums.unrealengine.com/t/cant-get-actor-to-face-direction-properly/467051/2 "2020-06-21T09:37:45Z")

</div>

Is it an actor, pawn or character? Are you using some movement component?

---

<div class="post-metadata">

**Author:** ![Strid\_By\_Swedork](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Strid\_By\_Swedork](https://forums.unrealengine.com/u/Strid_By_Swedork)\
**Post date:** [June 21, 2020, 9:57am UTC](https://forums.unrealengine.com/t/cant-get-actor-to-face-direction-properly/467051/3 "2020-06-21T09:57:21Z")

</div>

It’s a pawn (I said actor cause i mixed them up) the component is a UStaticMeshComponent

---

<div class="post-metadata">

**Author:** ![EvilCleric](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@EvilCleric](https://forums.unrealengine.com/u/EvilCleric)\
**Post date:** [June 21, 2020, 10:22am UTC](https://forums.unrealengine.com/t/cant-get-actor-to-face-direction-properly/467051/4 "2020-06-21T10:22:10Z")

</div>

- So, you’re not using any movement component?
- How are you moving the pawn? With AddActorLocalOffset?
- Where did you put the code above?
- Can you move diagonally?
- …

It would really be faster if you show us the pawn code.

---

<div class="post-metadata">

**Author:** ![Strid\_By\_Swedork](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Strid\_By\_Swedork](https://forums.unrealengine.com/u/Strid_By_Swedork)\
**Post date:** [June 21, 2020, 10:49am UTC](https://forums.unrealengine.com/t/cant-get-actor-to-face-direction-properly/467051/5 "2020-06-21T10:49:00Z")

</div>

PlayerComponent = CreateDefaultSubobject\<UStaticMeshComponent(TEXT("PlayerComponent "));

```
PlayerComponent ->SetupAttachment(RootComponent);

.
.
.
void APlayerPawn::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	FQuat quat = GetActorLocation().ToOrientationQuat();
	//UE_LOG(LogTemp, Warning, TEXT("MyCharacter's Location is %f"), rotation);
	OurVisibleComponent->SetWorldRotation(quat);

	{
		if (!CurrentVelocity.IsZero())
		{
			FVector NewLocation = GetActorLocation() + (CurrentVelocity * DeltaTime);
			SetActorLocation(NewLocation);
		}
	}
}
```

---

<div class="post-metadata">

**Author:** ![Strid\_By\_Swedork](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Strid\_By\_Swedork](https://forums.unrealengine.com/u/Strid_By_Swedork)\
**Post date:** [June 21, 2020, 10:50am UTC](https://forums.unrealengine.com/t/cant-get-actor-to-face-direction-properly/467051/6 "2020-06-21T10:50:18Z")

</div>

That’s pretty much the code i use.

---

<div class="post-metadata">

**Author:** ![EvilCleric](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@EvilCleric](https://forums.unrealengine.com/u/EvilCleric)\
**Post date:** [June 21, 2020, 10:58am UTC](https://forums.unrealengine.com/t/cant-get-actor-to-face-direction-properly/467051/7 "2020-06-21T10:58:50Z")

</div>

CurrentVelocity???

---

<div class="post-metadata">

**Author:** ![Strid\_By\_Swedork](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Strid\_By\_Swedork](https://forums.unrealengine.com/u/Strid_By_Swedork)\
**Post date:** [June 21, 2020, 11:07am UTC](https://forums.unrealengine.com/t/cant-get-actor-to-face-direction-properly/467051/8 "2020-06-21T11:07:21Z")

</div>

In .h file:  
FVector CurrentVelocity;  
in .cpp file:  
CurrentVelocity.X = FMath::Clamp(AxisValue, -1.0f, 1.0f) \* fDash;  
or

```
	CurrentVelocity.Y = FMath::Clamp(AxisValue, -1.0f, 1.0f) * fDash;

```

fDash is a float triggered by user input that determens player speed

---

<div class="post-metadata">

**Author:** ![EvilCleric](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@EvilCleric](https://forums.unrealengine.com/u/EvilCleric)\
**Post date:** [June 21, 2020, 11:22am UTC](https://forums.unrealengine.com/t/cant-get-actor-to-face-direction-properly/467051/9 "2020-06-21T11:22:15Z")

</div>

Remove the quat line and try this:

```
 //FQuat quat = GetActorLocation().ToOrientationQuat();
 //PawnMesh->SetWorldRotation(quat);

if (!CurrentVelocity.IsZero())
{
	FVector NewLocation = GetActorLocation() + (CurrentVelocity * DeltaTime);
	SetActorLocation(NewLocation);
	PawnMesh->SetWorldRotation(CurrentVelocity.ToOrientationRotator());
}

```

It will instantly rotate the component towards the CurrentVelocity’s direction.

---

<div class="post-metadata">

**Author:** ![zbugba](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zbugba](https://forums.unrealengine.com/u/zbugba)\
**Post date:** [June 21, 2020, 6:56pm UTC](https://forums.unrealengine.com/t/cant-get-actor-to-face-direction-properly/467051/10 "2020-06-21T18:56:55Z")

</div>

Well solution depends on how do you move your character. If you have your input vector e.g. you have pressed W meaning your movement vector is `FVector(0.0f, 1.0f)`. Then you need to normalize the vector (in case you have both W and D pressed you would get vector that is not normalized) by callinng `.Normalize()` function on your input vector. Then you call `.Rotation()` function on your normalized vector which returns `FRotator` stucture. The simply set your APawn rotation by calling `YourPawn->SetActorRotation(NewRotation)`.

---

<div class="post-metadata">

**Author:** ![zbugba](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zbugba](https://forums.unrealengine.com/u/zbugba)\
**Post date:** [June 21, 2020, 6:57pm UTC](https://forums.unrealengine.com/t/cant-get-actor-to-face-direction-properly/467051/11 "2020-06-21T18:57:01Z")

</div>

I’ve already answered your question, waiting for the moderator approval.
