- Home /
mouse controlled character
Hi guys, do know how to make a mouse controlled character ? For example, i clicked on one placed, after clicking, my character will move to that place.. thanks
Answer by cj_coimbra · Dec 07, 2011 at 07:34 PM
Get the clicked point with ScreenPointToRay. http://unity3d.com/support/documentation/ScriptReference/Camera.ScreenPointToRay.html
Tag your floor or whatever place you want your character to move. Then do a raycast with the previous ray to see if you clicked a valid moving position. http://unity3d.com/support/documentation/ScriptReference/Physics.Raycast.html
If so, set a target vector3 point for your character to move towards. You can get this point from the collision of the Raycasting previously done.
Then, move towards that point. http://unity3d.com/support/documentation/ScriptReference/Vector3.MoveTowards.html
Your answer