How do I set a rotation on an object between two points? Z-axis

I am spawning an object and I want to change its rotation every spawn. I have an object with a rotation in Z = 0 forward direction. I want to change it rotation randomly in the z axis between 225 and 135.

How make a random value between two points and pop it out? For the spawn

Something like either of these should work:

To rotate an object so it faces between two points (using Z axis / yaw in Unreal):

Simple way (Blueprint or C++)

Use Find Look At Rotation, then keep only Z:

Rotation = FindLookAtRotation(Start, Target)
NewRotation = (0, 0, Rotation.Yaw)

:backhand_index_pointing_right: This makes the object rotate only around Z (yaw) and ignore pitch/roll.


In Blueprint

  • Use Find Look At Rotation

  • Break Rotator

  • Make Rotator:

    • Pitch = 0

    • Roll = 0

    • Yaw = Yaw from result

  • Set Actor Rotation


In C++ (example)

FRotator LookAt = UKismetMathLibrary::FindLookAtRotation(Start, Target);
FRotator YawOnly(0.f, LookAt.Yaw, 0.f);
SetActorRotation(YawOnly);

Yes this was what I was looking for, thank you

You’re welcome.

1 Like