- Home /
RTS Controller?
I'm just getting into Unity with some friends, we are trying to build the player controls currently. We have our camera script working great (RMB rotates camera on mouse input) but we would like a Runescape/RTS style control for the player. I want the player to move to where ever you left click, I've written this code below but the player will move to where ever the camera is facing, not when you click and the player stops moving after you let go of left click.
var target : Transform;
function Update ()
{
var hit : RaycastHit;
if (Input.GetMouseButton(0))
{
if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), hit, 500))
{
var localHit = transform.InverseTransformPoint(hit.point);
target.Translate((hit.point - target.position) * Time.deltaTime);
}
}
}
Your answer
Follow this Question
Related Questions
Trigger move object only when player isn't looking at object 1 Answer
How to make "enemy" have a frustum(cone) view and not a circle radius 2 Answers
I want to click on my screen and make my character move there, having trouble with raycasts. 1 Answer
Raycast Destroys player. 1 Answer
Stop player movement if it's Raycast hits an object 0 Answers