x


How to make an enemy chase player, using collisions

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.

more ▼

asked Mar 16, 2011 at 09:08 PM

Stretch gravatar image

Stretch
3 3 2 5

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Place a rigidbody and use gravity

more ▼

answered Mar 16, 2011 at 09:26 PM

Ciaran 1 gravatar image

Ciaran 1
16 6 4 4

And to chase the player?

Mar 16, 2011 at 09:32 PM Stretch

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;
            
Mar 16, 2011 at 09:45 PM Ciaran 1
(comments are locked)
10|3000 characters needed characters left
more ▼

answered Mar 16, 2011 at 09:10 PM

DaveA gravatar image

DaveA
33.4k 417 336 443

That's a little too advanced. I'm not worried their feet being in the right place, I'm just using capsules.

Mar 16, 2011 at 09:24 PM Stretch
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4185
x3130
x1041
x502

asked: Mar 16, 2011 at 09:08 PM

Seen: 3742 times

Last Updated: Mar 16, 2011 at 09:08 PM