Hi everyone, I have a little problem that got stucked in a different question posted earlier this week. I have an enemy that follows the player when he's at a certain distance. The thing is that when the enemy is chasing the player, if he jumps, the Ai start to walk in the Y axis trying to reach the player in the air. How can I make the enemy follow the player, without walking in the air, keeping him on the ground, no matter if the player jumps or not?
Here's the script so far:
asked Jan 25 '11 at 07:31 PM
Like Scribe mentioned you should eliminate the y-part of the direction. That way your enemy turns just around the y-axis. I don't know what kind of game you try the make 2D sidescroll or 3D but anyway, it would be better to move your enemy with a charactercontroller or rigidbody. As far as i know if you set the position directly via Transform you bypass any collision detection. Add a characterController and use it's Move() function (works similar to Transform.Translate()). That would apply gravity to your enemy and it can walk ramps up and down.
The second line just eliminates the rotation around x and z. Now it's impossible for the enemy to rotate around these axes.