Why does your guard lean back to look up?

It faces you perfectly. Including up and down.

Why does your guard lean back to look up?

The problem

Facing the target, in 3D.

protected override void OnUpdate(){    var dir = Target.WorldPosition - WorldPosition;    WorldRotation = Rotation.LookAt( dir );}

Stand on a ledge and dir points up, so the whole body tilts back to face you.

The fix

Flatten it first.

Zero the height of the direction, so the guard only turns left and right.

dir→WithZ( 0 )→turns, never tilts

The fix in code

Flatten, then LookAt.

protected override void OnUpdate(){    var dir = Target.WorldPosition - WorldPosition;    var flat = dir.WithZ( 0 ).Normal;     WorldRotation = Rotation.LookAt( flat, Vector3.Up );}

Z is up in s&box. Our practice dummy turns to face its path exactly like this.

Watch out

Standing right on top of it?

If the target is straight above, the flat direction has no length. There's nothing to face.

dir.WithZ( 0 ).Length
check it first
Close to zero
keep the old rotation
Our lobby player
turns past 20 units

The rule

Face it flat.

Direction
target minus you
Flatten
WithZ( 0 ).Normal
Face it
Rotation.LookAt( flat )