- Home /
Point an arrow at the mouse position, 2.5D
I'm making a 2.5D archery game for a university project and having some trouble spawning the arrows pointing at the mouse position.
I'm working with the coords y=vertical, x=horizontal, z=depth (but not seen due to orthographic camera).
Essentially I want an arrow to be instantiated at the players position pointing at the mouse (the x,y of the mouse - where z is always 0), it should be simple enough although I'm having some real trouble with getting the rotation correct.
transform.LookAt doesn't seem to work too well in the 2.5d space.
Any help would be greatly appreciated, Hawk
Answer by BerggreenDK · Nov 16, 2011 at 10:43 PM
if you build your 2.5D univers in real 3D coords, the lookAt should work in both perspective and orthographic camera.
are you sure that your objects are aligned correctly to the right axis? Eg. if you export from Blender the Z and Y is oppersite and that could be the problem.
Regarding the mousepos, there is something called ScreenToWorld and WorldToScreen + a bunch of similar calculations/functions available for such translations.
Here is just one of them, I recommend you take a look at see if there is anything usefull in it.
http://unity3d.com/support/documentation/ScriptReference/Camera.ScreenToWorldPoint.html
Your answer
Follow this Question
Related Questions
rotation LookAt of 2D gameObject in 3D space 1 Answer
Why is my GameObject rotation snapping to a certain angle when he reaches its destination? 2 Answers
Locking the Z-axis based on direction 0 Answers
2d character, how to limit rotation to z, with character looking left? 0 Answers
Sprites always face the camera, Camera freely rotates 3 Answers