I have a basic script for an enemy to chase a player when the player gets near him. When the player "escapes" the enemy I would like the enemy to return to it's starting position.
I am having a little trouble storing the initial enemy starting position and getting the enemy to return there. The enemy successfully follows the player and stops following when the player gets too far away. But when the enemy is supposed to return to his start position I get an error.
Here is the relevant code (the game is top down view):
I have ommitted any code that isn't relevant. I also did a debug to check that ReturnPosition() was being run and it is.
The error I get is:
Thanks for taking a look.
Looks like the error comes from this line :
Because you're storing your startPosition variable as a Vector3 (transform.position) and then later you're referencing it as startPosition.position. That means what you're really calling is transform.position.position.
I would change your startPosition variable so its declared as something, so do
private var startPosition : Vector3;
then use your startPosition = transform.position
And then in the code, instead of using startPosition.position, just do startPosition.
should do the trick, and cut down some processing time by declaring the variable as an actual type.
answered Feb 07 '11 at 05:43 PM