- Home /
Following Script Not Working Properly
Hey guys, i have a problem with my script here, the script works but when the enemy follows me it keeps descending with as result going trough the terrain (putting the model higher doesn't work) other then that the script works perfectly fine. Thanks in advance.
The Script:
#pragma strict
function Start () {
}
//target to follow
var target : Transform;
//Checks his position
var pos : Transform;
//Ray variables
var rayLength : float = 3;
//Speed
var speed : float = 4;
//Move
var move : boolean = false;
function FixedUpdate() {
}
function Update() {
var fwd = transform.TransformDirection (Vector3.forward); var hit : RaycastHit;
if (renderer.isVisible)
{
move = false;
}
if(!renderer.isVisible)
{
move = true;
}
//Follows meh i don't watch him
if(move)
{
//Look at target
transform.LookAt(target);
//Follow meh
pos.position += pos.forward * speed * Time.deltaTime;
}
//Temp avoidance
if (Physics.Raycast (transform.position, fwd,rayLength)
&& move)
{
Debug.Log("Moving.");
transform.Translate(Vector3.right * 3 * Time.deltaTime);
}
}
So, when it's following you, it goes in your direction but keeps moving down slightly?
I was able to fix the sinking, but now he does the same thing in the air. (He flies)
Answer by Ruffy789 · Aug 25, 2012 at 02:16 PM
I think i fixed it by adding a Box collider with Rigidbody and enabling gravity. There are no worries now as in the game he won't be going over steep things.
Your answer
Follow this Question
Related Questions
Script working on some objects but not others 1 Answer
Pickup script not workimg 0 Answers
Can't get bullet to spawn and move 1 Answer
Door script not working when door is turned 90 degrees 1 Answer
Walking script not working need help 1 Answer