# How do you Rotate towards an object on ONE axis using a Rigidbody?

I’m having quite a bit of trouble getting the hostiles in my game to rotate towards the player. At the moment I have this:

``````        if(distanceFromPlayer <= aggroDistance && distanceFromPlayer > attackDistance)
{
Vector3 direction = (player.transform.position - transform.position).normalized;
Quaternion targetDirection = Quaternion.LookRotation(direction);
Quaternion deltaRotation = Quaternion.Slerp(transform.rotation, targetDirection, walkSpeed * Time.fixedDeltaTime);
rb.MoveRotation(deltaRotation);
rb.velocity = transform.forward * walkSpeed;
}
``````

What this is doing here is rotating the RigidBody towards the player on ALL THREE axis and then moving forwards. At the moment this causes the hostile game object to leave the ground and walk in the air if the player jumps for example. What I want is for the hostile to stay grounded AND to keep gravity, rotations and axis UNLOCKED.

Thanks a lot for the help!

You can use the Euler angles to update only one axis of rotation:
rb.MoveRotation(Quaternion.Euler(new Vector3(rb.rotation.x, deltaRotation.eulerAngles.y, rb.rotation.z)));