Quantcast
Channel: Questions in topic: "follow"
Viewing all articles
Browse latest Browse all 536

I can get a sprite to look at my mouse but not another Vector3, im not doing anything wrong but the sprite just looks in one direction.

$
0
0
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);

Viewing all articles
Browse latest Browse all 536

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>