Hi, I have a 2D object that continuously looks at the mouse cursor. I am using an overheard view. Here is the code that I used for this:
Vector3 screen_pos = Camera.main.ScreenToWorldPoint (new Vector3 (mouse_pos.x, mouse_pos.y, 0));
transform.LookAt ( screen_pos, Vector3.forward);
Before I changed to using the mouse cursor I was just using left/right arrow keys to rotate the object and I was able to instantiate bullet objects using this code:
Instantiate (BulletPrefab, transform.localPosition+(transform.up *.5f)+(transform.right*-.3f) , transform.localRotation); // bullet instantiates from front right
The above code worked fine before but now with the mouse cursor code added in, the bullets move in random directions and sometimes instantiate in the wrong position.
Thanks.
↧