Need help creating FPS chase script

Hi y’all,
Noob here looking for help on how to make FPS(player) chase and catch fleeing enemy. I have read through a lot of AI tuts that seem to cover only the enemy chasing the FPS(player). Couldn’t find any with the FPS(player) chasing the enemy…

Any help would be great!

Thanks,
asg

So you want to script the player to chase someone?
I’m confused XP

Hi Warrior,
Thanks for responding! That’s exactly what I am looking for…

var target : GameObject;

function Update ()
{
transform.Translate(target.transform.position);
}

Just drag your enemy onto “target”
and it should do the trick.
I might have gotten something messed up. but thats the basic idea.

EDIT:

It won’t give you pathfinding or anything but It will move to the enemys location.

Just put the script you would have if it were an NPC on the FPS Controller and disable control of it.

Thanks MrDusk and Warrior!
Much appreciated. You guys on this forum are Awesome! Going to try to get this working tonight…I now have renewed energy!

Thanks again guys!

Hi Warrior and Mr. Duskling,
Anthony here. Thought i had a good handle on how to do this and after failing miserably I thought I would bother you a bit more. What I am trying to do is:

Make camera/fps follow an enemy along a path and catch the enemy if it gets within a certain distance. Example would be a plane dogfight where one plane(which is the camera and fps) is chasing the enemy plane as it tries to evade and locks on and shoots if close enough.

I know how to move the enemy along a path, but struggling with how to do the above.

I am really trying to learn as much as I can about Unity and this forum has been invaluable to me.

Thanks for the help!

Okay, from what I can gather from your above explanation:

use transform.Translate(); to move towards the enemys position, and then, if the distance between them is less than or equal to x, do such and such.

http://unity3d.com/support/documentation/ScriptReference/Vector3.Distance.html

Thanks Dusk,
I think I am getting it. What I want is the player(fps) would be automatically following the enemy at a set speed on the z-axis, slightly behind him. The enemy would be trying to evade by going up, down or side to side and if the player can follow him close enough for a few seconds, the player can lock on and shoot… I am a pretty decent designer/animator, but lacking in the scripting department.

So I guess you are trying to program some basic AI.

If you are lacking in the script department, I wouldn’t continue with this project. You should go and read a book about unity, grasp some skills with scripting, and then come back and you will see the whole project in a different and more efficient perspective.

Good advice! I’m searching for a good book right now. There seem to be a few out on the market. Any suggestions?