Help with a chasing script

I am trying to get an enemy to chase a vehicle and get close enough to collide. All the other scripts and questions all have just following and stopping at a certain distance I can’t seem to find one that just follows and even if the player stops it keeps going and rams into the player. Please help and if possible could you explain what exactly is happening so I can know why certain things I was trying weren’t working. THANK YOU!

If your problem is solved please accept an answer. If not please give an update on what changed.

2 Answers

2

ok… you’ve requested for something simpler than what you have found lol. all you need to is use RotateTowards and MoveTowards to get started you can make it fancier as you get confident. of course you want the enemy to be moving towards the player. so you will need to reference the player somehow. you can do this by using FindObjectsWithTag, then casting it as a GameObject. from there you can get the transform(vector3) you need.

good luck, besure to check Burzerg’s tutorial on this

none of that helped me I watched both of the AI video tutorials and tried everything that I could think of and still just got it where it follows and as soon as it got to a certain range stopped and if I went backwards it rotated around the car and appeared in front of the player.

Please don't post comments as Answers - I've converted them for you this time.

it shouldn't be stopping until it ends up on you exact position(inside of you). it sounds like you have a child object off center to a parent one and referencing the parent making the object stop because it on the parent but not the child. or you doing a distance code without realizing. or you have a another collider in the way.

I just quickly searched unity chasing script in google and found this: How to make enemy chase player. Basic AI - Questions & Answers - Unity Discussions

Just use this and set MinDist to 0 or just remove that entire if(… <= MinDist)

Another thread which i found as well is this: http://forum.unity3d.com/threads/34046-Follow-Chase-Player if the answer for some reason is not enough.

Hope this helps

Are you sure the one who chases the player doesn't stop because they hit the collider of the player or the collider of the follower? Also make sure that no other script is interfering with the FollowChaseScript and makes it stop before it gets too close to the player. I tried the FollowChaseScript from the forum and it worked for me. I made a cube with a rigidbody+box collider as the follower and the First Person controller as the leader. The cube caught up to the player and made the player pushed around the place.

ExTheSea it does follow and register that I have hit my player character but now using that forum code my enemy floats slightly in the air and blinks back and forth from in front and behind the player at a certain distance away and I do not have a box collider on my player and the box collider i have on my enemy is tight against the cubes that are making the front of the enemy. And before I get scolded again I would comment this but there is no COMMENT BUTTON like the tutorial video says there should be.