tags:

views:

38

answers:

1

I'm coding some critter AI for a game i am working on for my Unity 3D project. I have no programming background and have been stumbling through this using tutorials and other peoples scripts.

My problem is that i want my critter to run directly away from the player when the player kicks it.

I need the dodo to run directly away from the player when kicked, and i dont know the math nor the syntax to calculate that angle. They are two characters moving independently through worldspace.

Here is what i got so far:

waypoint = (fleeWP.transform.position);

transform.LookAt(Vector3(waypoint.x, transform.position.y, waypoint.z));      
transform.Translate (Vector3.forward * speed * Time.deltaTime);

This currently makes the critter move towards the waypoint, rather than away. I might be attacking this all wrong. Please chastise me.

+1  A: 

Just invert the translation:

transform.Translate (Vector3.forward * speed * Time.deltaTime * -1);
Ignacio Vazquez-Abrams
I tried that, but that makes the dodo run backwards. I'd like it to look in the direction its running.
donthackmyacc
Using Ignacio's code should fix the direction of the dodo for you.Now, just invert the LookAt.transform.LookAt(Vector3(waypoint.x * -1, transform.position.y * -1, waypoint.z));
Vladislav
The Lookat uses worlspace coordinates, so giving them the negative sets the waypoint at the negative side of origo. So he no longer looks at the player but at the players position in negative space.
donthackmyacc
anyone that can help?
donthackmyacc
Calculate the translation from the dodo to the player, invert that, add it to the dodo's position, then face that.
Ignacio Vazquez-Abrams