I have a problem with click to move script.
I use now this:
var speed = 1;
var targetRadius = 0;
private var target : Vector3;
var hit : RaycastHit; //added
function Start () {
rigidbody.freezeRotation = true;
target = transform.position;
}
function FixedUpdate () {
if (Input.GetButtonDown ("Fire1")) {
ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, hit)) {
animation.CrossFade("walk"); //added
target = hit.point;
}
}
if (Vector3.Distance(transform.position, target) > targetRadius) {
transform.LookAt(target);
transform.Translate(0,0,speed);
target.y = transform.position.y;
}
}
But its doing very weird, when i start my game the character is bouncing and doing strange moves…
And than the character is under the terrain.