- Home /
Google is your friend
third person shooter player follow the crosshair
hi , im having a hard time finding a correct way to make the hero looking straight to the cross hair when pressing the mouse button (like in dead space or gta ) i thought using a look at script type but haven't succeed. i was hoping that someone could show me how to make it happened or just point me to a tutorial on it.
i have understanded your problem statement what you want is
Cam = GameObject.FindGameObjectWithTag("$$anonymous$$ainCamera");
Player.transoform .rotation = Quaternion.Slerp(Player.transform.rotation,Quaternion.Euler(new Vector3(Player.transform.rotation.x,Camera.rotation.eulerAngles.y,Player.transform.rotation.x));
this line of code will make your player rotation linear with camera
Answer by Firedan1176 · May 31, 2014 at 10:34 PM
If you use LookAt, you'd have to make sure the crosshair is touching the object he's aiming at. I would say the best way to go about doing this is to use Raycast (Look up physics.RaycastAll). If you shoot a raycast when the user clicks, you can use RaycastAll to get the hit point (where the raycast hits an object) and have the gun use Look At to look at the hit point.
(I went through a little time to draw you an example below)
hmmm(i might bad explained ) sorry but its not what i wanted But it is a neet example to use later on my project . but what i really wanted is to rotate the player in the direction of the camera . ( each time you turn the camera the player follows the camera axis.
tell me if its still bad explain ( im really bad in explanation's in English)
same as always tutorial link will also help me ( and direct script example also).