Trouble controling object rotation LookAt and MoveTowards

After reviewing a ton of posts related to this, I must now just ask for help. :wink:

Plain and simple. An object rotating and moving towards another object. I’m using LookAt for the rotation, and Vector3.MoveTowards for the motion but as the first object closes on the second, it vectors upwards on the Y axis and for the life of me I cannot grasp how to stop it. It is rotating towards the object properly though.

I’m using this code currently, but previously I tried position instead of localPosition and same result.

object.transform.position = Vector3.MoveTowards (object.transform.position, player.transform.localPosition, objectMoveSpeed);

Anyone know how I can keep that object on the ground?

It looks un-intuitive for me to see you’re mixing world and local space coordinates. Perhaps it doesn’t matter in your setup, but it’s strange to read the code like that.

Anyway, what you describe sounds like you want to look at an object, but not allow rotation in any axis but Y? A solution would be to look at a position which has the same Y as yourself.

var playerAtSameHeight = player.transform.position;
playerAtSameHeight.y = obj.transform.position.y; // Use the same height as obj