- Home /
Some wierd problem.
okay so the code below works... except for one problem...
he wont face toward the player and he seems to "Run away" from the player insted of move towards him. and when he stops sometimes he just spins endlessly... and stops moving around all together.
help? var target : Transform; //the enemy's target
var moveSpeed = 10; //move speed
var rotationSpeed = 3; //speed of turning
var myTransform : Transform; //current transform data of this enemy
function Awake()
{
myTransform = transform; //cache transform data for easy access/preformance
}
function Start()
{
target = GameObject.FindWithTag("Player").transform; //target the player
}
function OnBecameInvisible () {
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
Answer by whydoidoit · Jul 13, 2012 at 07:09 AM
You are using transform.forward but you are never pointing the enemy at the target:
function OnBecameInvisible() {
myTransform.LookAt(target);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
Also OnBecameInvisible is going to be called only once when the item becomes invisible - is that what you want? For it to only move once? Because you could set a ImInvisible flag and have it move in Update.
yes thats what i want. for him to move once off camera... i got that all working this was solved. after this was solved, problem 2 came up. the problem with the noclipping.
Your answer
Follow this Question
Related Questions
Variable Script "movement" 2 Answers
Sphere falling through floor 11 Answers
Switch Case for Basic AI.... 1 Answer
The referenced script on this behavior is missing! 2 Answers