Hello guys i want to ask a question. Is there any script to click and move to a point?
I found a script ClickToMove in unify (unity wiki) but i have a problem… when i press on a far distance my character goes to that point very fast but when i press to a short distance my character goes slow. I want to be the same speed at all distances. And if its easy how can i make the animation plays when the character is between the starter point and the clicked point? Like walk animation and when he goes to that clicked point to play the animation idle.
Thank you for the help…
Here is the script which i found on unity.If there is a way so you can edit it to keep the speed same on all distances i will be happy
// Click To Move script
// Moves the object towards the mouse position on left mouse click
var smooth:int; // Determines how quickly object moves towards position
private var targetPosition:Vector3;
function Update () {
if(Input.GetKeyDown(KeyCode.Mouse0))
{
var playerPlane = new Plane(Vector3.up, transform.position);
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hitdist = 0.0;
if (playerPlane.Raycast (ray, hitdist)) {
var targetPoint = ray.GetPoint(hitdist);
targetPosition = ray.GetPoint(hitdist);
var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
transform.rotation = targetRotation;
}
}
transform.position = Vector3.Lerp (transform.position, targetPosition, Time.deltaTime * smooth);
}