I add character controller to scene, and try to make it to patrol. Moreover character should rotate over terrain. And how can I provide coordinates of Point(to move) as direction. In my case it doesn’t work, character moves rapidly somewhere
var i: int;
public var point_arr: Vector3[];
var point_move: Vector3;
var myTarget:GameObject;
var myDistance;
var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 10.0;
var normal_q: Quaternion;
var terr_q: Quaternion;
var moveDirection:Vector3;
function Start(){
i = 0;
point_move = point_arr[0];
}
function myMove(mytarget: Vector3){
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded) {
moveDirection = transform.TransformDirection(mytarget);
//moveDirection *= speed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
var hit: RaycastHit;
if(Physics.Raycast (transform.position, -Vector3.up, hit, 10.0))
{
normal_q = Quaternion.FromToRotation(Vector3.up, hit.normal);
terr_q = normal_q * Quaternion.AngleAxis(transform.rotation.eulerAngles.y, hit.normal);
transform.rotation = Quaternion.Slerp(transform.rotation, terr_q, Time.deltaTime);
}
}
function Update() {
point_move = point_arr*;*
point_move.y = transform.position.y;
myDistance = Vector3.Distance(transform.position,point_move);
if(myDistance>1){
myMove(point_arr*);
_}_
else{
if(i==point_arr.length-1){i=0;}
else{i ++;}
_}*_
}
Thanks