- Home /
Enemy following the target with ITween
I'm trying make the enemys follow my player (the "alvo" target object in script), but the behaviour is odd...
The code:
public void Perseguir()
{
if (avistou == false) return;
if (estado != InimigoEstado.ieCorrendo)
{
estado = InimigoEstado.ieCorrendo;
animation.Play("correndo");
}
iTween.LookTo(gameObject, alvo.transform.position, 0.4f);
iTween.MoveTo(gameObject, Vector3.forward, 2f);
}
Some idea ?
Answer by Statement · Mar 24, 2011 at 07:14 PM
I am not an iTween user, but from the method name (MoveTo), it sounds you should pass the position it should move to, not the direction it should move to.
iTween.MoveTo(gameObject, alvo.transform.position, 2f);
Or if it does need a direction, maybe you need transformed forward direction?
iTween.MoveTo(gameObject, transform.forward, 2f);
Answer by Paul 7 · Mar 24, 2011 at 07:17 PM
If you function is getting called multiple times then multiple iTween scripts are going off at the same time. Make sure that function is only getting called once.
If Perseguir() is getting called more then once, then multiple copies of the iTween animations are going to get added to the object. For example, if Perseguir() gets called, then next update it gets called again, you are going to have 2 $$anonymous$$oveTo animations on your gameobject. I am not sure how you did it. I am just letting you know if the function is getting called multiple times it is going to give you an odd behavior. I actually think Statement is right and you arent giving the position of where you want him to go. You are trying to move it forward in the Z position.
Your answer
Follow this Question
Related Questions
Enemy Follow Script Help 2 Answers
AI enemy Stuck at corners 2 Answers
How to make an AI like slender ? 1 Answer
AI Following Problem 1 Answer