Search Unity

how to make an auto targeting system for an action adventure

Discussion in 'Scripting' started by gogopie, Jun 25, 2010.

  1. gogopie

    gogopie

    Joined:
    Jun 25, 2010
    Posts:
    11
    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?
     
  2. Skatt

    Skatt

    Joined:
    Jun 25, 2010
    Posts:
    42
    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.
     
  3. Aiursrage2k

    Aiursrage2k

    Joined:
    Nov 1, 2009
    Posts:
    4,835
    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.
     
  4. gogopie

    gogopie

    Joined:
    Jun 25, 2010
    Posts:
    11
    Thanks for the advice. It's a little over my head though. do you think you could show me an example?
     
  5. Aiursrage2k

    Aiursrage2k

    Joined:
    Nov 1, 2009
    Posts:
    4,835
  6. gogopie

    gogopie

    Joined:
    Jun 25, 2010
    Posts:
    11
    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.
     
  7. ColossalDuck

    ColossalDuck

    Joined:
    Jun 6, 2009
    Posts:
    3,246
    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.
     
  8. gogopie

    gogopie

    Joined:
    Jun 25, 2010
    Posts:
    11
    Alright. Thanks for the info. I've already done a few tutorials and have started to have a slight grasp of the program.