- Home /
Moving gameobject with script isn't working
Ok so first off, i didn't create this script on my own its like AI and i'm not that good yet so i don't COMPLETELY know how it works. I get most of it but i couldn't make it on my own. Anyway, the only important part you need to look at is in the function chase, and the variable gravity. According to the script it should make the object go down at a steady speed according to the value of a float variable. It doesn't do it i don't know why. Remember the important function is function chase and variable gravity. Heres the script,
var Distance : float;
var Target : Transform;
var lookAtDistance = 25;
var chaseRange = 15;
var attackRange = 1.5;
var moveSpeed = 5;
var Damping = 6;
var controller : CharacterController;
var gravity : float = 20;
private var moveDirection : Vector3 = Vector3.zero;
function Update(){
Distance = Vector3.Distance(Target.position,transform.position);
if(Distance < lookAtDistance){
lookAt();
}
if(Distance > lookAtDistance){
renderer.material.color = Color.green;
}
if(Distance < chaseRange){
chase();
}
}
function lookAt(){
renderer.material.color = Color.yellow;
var rotation = Quaternion.LookRotation(Target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Damping);
}
function chase(){
renderer.material.color = Color.red;
moveDirection = transform.forward;
moveDirection *= moveSpeed;
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
function attack(){
}
Can you put a debug log statement in there and confirm that the function chase is being called multiple times?
"It doesn't do it i don't know why". what is it exactly that it is not doing: not moving in the correct direction, not moving at all, etc.?