- Home /
How Do I Make My Weapon Follow My Cursor?
I'm currently working on a 2D game and I am trying to create a weapon that points at the different my cursor is pointing at, meaning if I move my cursor to the right, I want the gun to point to the right, if I move the cursor to the left, I want the gun to point to the left, same thing with the up and down direction, does anyone know how to create that? Thanks in advance.
I believe what youre looking for, I already explained to someone else a while ago. Check this out.
Actually, scratch that, because your game is 2D and i get what you mean now. Well you can get the current position of your mouse by writing Input.mouseposition
or something and then you can basically use transform.LookAt(Input.mouseposition);
to make your gun always face the cursor.
Oh i see, thanks because I really didn't know how to get the input of where my mouse, thanks and take care.
Also look at this post https://answers.unity.com/questions/654222/make-sprite-look-at-vector2-in-unity-2d-1.html
Your answer
Follow this Question
Related Questions
Trying to find the highest number than add it to itself. 2 Answers
IEnumerator Loop on keypress 1 Answer
Slowly increase motor.force 1 Answer
Move from A to B after recieving touch input 1 Answer
Need help fixing my script 1 Answer