there’s a problem I’ve encoutered:
When I’m standing on the terrain which its surface’s height is really high(like a mountain) and moving to a low height so it like flies to that hit.point and not ‘walks’ to it…
private var speed = 1;
var object : Transform;
var hit : RaycastHit;
var movePosition : Vector3;
var moving : boolean = false;
animation.wrapMode = WrapMode.Loop;
function Update(){
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, hit, 3000) hit.collider.tag == "Terrain" Input.GetButtonDown("Fire1")) {
if(moving)
{
movePosition = hit.point;
}else{
movePosition = hit.point;
MoveObjectToString();
}
}
}
function MoveObjectToString() {
moving = true;
while(Vector3.Distance(movePosition, transform.position) > 0.1){
animation.CrossFade("walk");
var controller : CharacterController = GetComponent(CharacterController);
var direction : Vector3 = movePosition - object.position;
controller.SimpleMove(direction * speed);
yield;
}
animation.CrossFade("idle");
moving = false;
}