how to make an auto targeting system for an action adventure

I’m trying to make a game sort of like legend of zelda.
I want to make a script that has the player look at an enemy if it comes into a certain range of the player. If there are more than one enemy in the player’s range I want the player to look at the enemy that’s the smallest angle away from the player. I’m very new at this so could you explain it to me with that in mind?

If you want your model to respond to this it must have a tracking bone for the head/eyes or whatever. Then you would just move the bone to the preferred target.
To find the target, it would be easiest to just set up a detection range and keep updating it as enemies are defeated.
This it not an easy task to undertake, but you could find what you need in the 3D Platformer tutorial. The enemies have detection.
Once you have some code failing on you come back and I’ll try to help more.

Heres a way.

Give every enemy a trigger.

In the enemy script, send the playerScript a message whenever the player enters the trigger (the player script will than add the enemy to the list), if the player exits the enemy trigger send another message (and the player will remove him from its list).

If you gave every enemy a trigger than you can set there “agro range”.

You could also develop a “buddy system”, suppose there is a group of 3 enemies, only 1 of the enemies is close enough to the player to trigger its AI, the other 2 are out of range. It would be easy for you to expand this system so that the one guy calls out to his buddies so all 3 of them come.

If thats not needed you might just give the player the trigger.

Every frame (or whatever) simply iterate through the list of enemies and find the enemy who has the closest angle.

This way you have battle-mode music as well as non-battle music.

Thanks for the advice. It’s a little over my head though. do you think you could show me an example?

Here you can see I made a demo of it (started doing it).

You can move around with the arrow keys/WASD

The enemy blocks will move close to you. The closest block will go twice as big and the light will change red if you have an enemy in range.

http://inanegames.ca/BattleSys/battleSys.html
http://inanegames.ca/BattleSys/battleSystem.rar

Thanks so much for taking the time to do that.
And also for you and anyone else, how did you get started doing this. It’s all very complicated an I want to know if there is a place to get started with programming because as I said before, I’m very new at this.

Start here, follow the basics and some of the tutorials. It will help you a lot.

Then from there I recommend you just use the scripting reference and try things out. When you get stuck and have questions, come here :). When you get good and such, help other people.

Welcome to the community.

@aiursrage2k That gives me a few ideas for games.

Alright. Thanks for the info. I’ve already done a few tutorials and have started to have a slight grasp of the program.