Player is a FirstPersonController running around on a terrain. I want the enemies to be similar, they just look at and move toward the player, reacting to the terrain in much the same way as the player.
I got the enemy chasing the player using it's transform.LookAt and transform.Translate but of course it moves in 3D space rather than along the ground.
So how is this achieved? I assumed using the rigidbody.velocity but none of the myriad of things I tried worked.
Any help/links appreciated.
Answer by Ciaran 1
Mar 16, 2011 at 09:26 PM
Place a rigidbody and use gravity
And to chase the player?
I tohught you said you had the enemy chasing the player?
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
//move towards the player
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
Answer by DaveA
Mar 16, 2011 at 09:10 PM
This is a good place to start: http://unity3d.com/support/resources/unity-extensions/locomotion-ik
That's a little too advanced. I'm not worried their feet being in the right place, I'm just using capsules.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
To help users post good questions and use the site effectively we have posted a user guide. Please check it out.
Answers and Comments
No one has followed this question yet.
Make 2 enemies not collide with each other and player
Enemy Cube going through walls.
Destroy Enemy Rigidbody after Jumping on Head?
Help with kinematic NPCs following non-Kinematic player and avoiding obstacles
Rigidbody Enemy and Collisions