- Home /
Question by
yxela007 · Nov 25, 2013 at 04:55 AM ·
charactergravitypatrolnormalized
Gravity not working with AI
Whenever I run this script, and the character goes over a hill or something, he descends really slowly. I'm not 100% sure what the moveDirection.normalized thing does, so that's probably the problem. Is there something I can add to this or change that will make the character it's attached to adhere to gravity?
#pragma strict
var theEnemy : Transform;
var checkpoints : Transform[];
var charController : CharacterController = theEnemy.GetComponent(CharacterController);
var currentCheckpoint = 0;
function Awake(){
currentCheckpoint = 0;
}
function FixedUpdate(){
var currentDistance = Vector3.Distance(checkpoints[currentCheckpoint].position, theEnemy.position);
var speed = 10;
var moveDirection = checkpoints[currentCheckpoint].position-theEnemy.position;
if(currentCheckpoint < checkpoints.length){
theEnemy.LookAt(checkpoints[currentCheckpoint]);
if(currentDistance<10){
currentCheckpoint++;
}
else{
charController.Move(moveDirection.normalized * speed * Time.deltaTime);
}
}
if(currentCheckpoint == checkpoints.length){
currentCheckpoint = 0;
}
}
Comment