Question by
CrazyLule · Aug 26, 2016 at 12:47 PM ·
mouselookmouse position
How do I make my player look and make my bullet move at direction of my mouse
So , how do I get the position of mouse and how do I make my bullet move at direction of the set position of mouse , and how do I make my player look at the direction of mouse ?
Comment
Answer by DavidWatts · Aug 26, 2016 at 02:19 PM
You can get a ray from the mouse position looking in the direction by using Camera.ScreenPointToRay https://docs.unity3d.com/ScriptReference/Camera.ScreenPointToRay.html then you use Phyics.Raycast to cast the ray. so you can have something like
Ray ray = Camera.main.ScreenPointToRay( Input.mousePosition );
RaycastHit hit;
Physics.Raycast( ray, out hit );
if( hit.collider != null ) {
transform.LookAt( hit.point );
}