I want a sprite to follow my player and i found some code to follow my mouse and the sprite looked at it wherever he was, however, when i changed out the variable for the mouse position to t, he vector3 storing my players location it looks in one direction, not even a point. I dont knwo what im doing wrong. Here are the two bits of code, firstly the one that tracks my mouse.
mousePosition = Input.mousePosition;
mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
//transform.LookAt(new Vector3(mousePosition.x, mousePosition.y, transform.position.x)); <---- THIS LINE WAS COMMENTED OUT BUT IT WORKS EITHER WAY
Quaternion rot = Quaternion.LookRotation( transform.position - mousePosition, Vector3.forward );
transform.rotation = rot;
_______________________________________________________________________
And here is the edited code for following my sprite.
var mousePosition = shipLoc;
mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
transform.LookAt(new Vector3(heroX, heroY, -10));
var rot = Quaternion.LookRotation(transform.position - mousePosition, Vector3.forward );
transform.rotation = rot;
transform.eulerAngles = new Vector3(0, 0,transform.eulerAngles.z);
↧