- Home /
Geometry Wars game experience in Unity
Hi, I building a game Geometry Wars like; I want to be able to rotate the "player" when moving the mouse to aim to the enemies. I'm using the MouseLook script as an start point but it's not working for me as the "player" rotating is not in synch with the mouse movement.
Answer by Jesse Anders · Sep 07, 2010 at 11:41 AM
Orienting an object towards the mouse position is a topic that's discussed frequently in the forums. Try searching the forums for (e.g.) 'aim at mouse'. Also, check out the EvacCity tutorial, as it shows how to do this (including code).
Note that if the player is not always located at the center of the screen, you may need to tweak things a bit. In short, the player and mouse position need to be expressed in the same space for the purpose of determining the rotation (this could be screen space, or world space - whichever you prefer). Once you have the positions in the same space, compute the vector from the player position to the mouse position, and then use Transform.LookAt() to aim the player at the cursor. (You can also compute the angle using Atan2() and rotate the player accordingly if you prefer.)
Answer by Dimitar · Dec 27, 2010 at 09:29 AM
If You haven't found anything try to get some ideas from that demo island they made. The camera could give you some "Lightbulb"
Your answer
Follow this Question
Related Questions
Screen.lockCursor messes my rotation 1 Answer
restrict mouselook X movement script does not work 4 Answers
Using quaternion for mouse movement? 3 Answers
Lock rotation on Z Axis 1 Answer