Quantcast
Channel: Answers for "Firing at mouse position, 2d game"
Viewing all articles
Browse latest Browse all 4

Answer by BDP1

$
0
0
Thank YOU! This code works perfectly!! function Update () { var mousePos = Input.mousePosition; mousePos.z = 32; //The distance from the camera to the player object var lookPos : Vector3 = Camera.main.ScreenToWorldPoint(mousePos); lookPos = lookPos - transform.position; var angle : float = Mathf.Atan2(lookPos.y, lookPos.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); } Wish I searched a little harder because this has been asked before!

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles



Latest Images