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

Answer by LyanApps

$
0
0
Are you moving the camera position as well? You can use Input.mousePosition to get the location of your mouse on each frame. http://docs.unity3d.com/Documentation/ScriptReference/Input-mousePosition.html var relative = gun.position - Input.mousePosition; gun.rotation = Quaternion.Euler(0,0, Mathf.Atan2(relative.y, relative.x) * Mathf.Rad2Deg); You'll have to align your coordinate systems with this though. http://docs.unity3d.com/Documentation/ScriptReference/Mathf.Atan2.html

Viewing all articles
Browse latest Browse all 4

Trending Articles



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