|
Hi, guys. I need your help. I have one game object and a point on space that I got from a Ray casted from the main camera. I tried very hard to make this object aim to that point just in the forward axis, like a Sidescroller shooter, where the mouse pointer is the aim of the gun (up and down only). I tryed everything but something is wrong.. please advise. Appreciate any help!
(comments are locked)
|
|
What's wrong with Transform.LookAt? if the object's center and the point are on the correct plane (defined by the object's up vector and it's center, if I understand correctly), or said differently, if both object and point have y == 0, it should be ok. The problem is that the target point is obtained by the X and Y position of the mouse, and the Z position can vary on the depth that of the surface the Raycast hit returns to me.. I need to ignore the Z and only get the X and Z position. Thats why the LookAt does not work =/
Mar 08 '12 at 01:57 PM
ronaldosilva
Ok. Then, you can use an empty gameObject with a box collider that covers all the floor (something like (50,1,50)) with a specific layer then you cast the ray only on that layer, that way the Y won't change. You can use Plane.Raycast as well, which return a distance and the hit point is calculated by ray.origine + ray.direction.normalized * distance. Finally, you can use Vector3.Scale( Camera.main.ScreenToWorldPoint(mousepos), new Vector3(1,0,1) ). If the camera is orthographic.
Mar 08 '12 at 04:42 PM
Berenger
Wow! Thank you! =)
Mar 08 '12 at 10:27 PM
ronaldosilva
(comments are locked)
|
