First off I would like to say that I know this question is common and has been asked many times over however, I have spent the majority of the day looking at posts and trying everything that I have come across and still no dice.
The problem that I am having is that I am trying to have 1 sprite chase another sprite and rotate toward the chased sprite. Everything that I have tried still rotates the object on the x and the z axis.
Here is some of the things that I have tried.
void Update()
{
transform.position = Vector3.MoveTowards(transform.position, _player.position, Time.deltaTime * _speed);
// ATTEMPT
//find the vector pointing from our position to the target
//var _direction = (_player.position - transform.position).normalized;
////Set x and y planes to 0 for the direction.
//_direction.x = 0;
//_direction.y = 0;
////create the rotation we need to be in to look at the target
//var _lookRotation = Quaternion.LookRotation(_direction);
////rotate us over time according to speed until we are in the required rotation
//transform.rotation = Quaternion.Slerp(transform.rotation, _lookRotation, Time.deltaTime * 1);
// THIS CODE GIVES ME VIEWING VECTOR IS 0 ERROR AND NOTHING ROTATES
// END ATTEMPT
// ATTEMPT
transform.LookAt(transform.position + new Vector3(0, 0, 1), _player.position);
// THIS CODE DOESN'T FLIP THE OBJECT OVER BUT MAKES THE SPRITE'S MIDDLE POINT FACE THE OBJECT AND I HAVE CHANGED THE ANCHOR POINT TO THE RIGHT OF THE SPRITE
// END ATTEMPT
}
I have tried several other ways of doing this as well and just didn’t want to post a ton of code. All of them either make the sprite point from the center of the sprite or they flip the object over on either the x or y axis or both. Any help with a good explanation would be greatly appreciated Thank you very much in advance.