Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to make an AI RUN AWAY FROM PLAYER?

Discussion in 'Scripting' started by Claymore, Dec 26, 2014.

Thread Status:
Not open for further replies.
  1. Claymore

    Claymore

    Joined:
    Oct 17, 2012
    Posts:
    158
    Okay i give up,i have checked the iwhole nternet (unity answers,forum...) in 3 days and i haven't found ANYTHING USEFUL.

    So here we go: How can i make AI Run Away from me if i enter in "trigger" or "zone" or whatever,it doesnt matter what triggers it,but what matters is HOW it is done,what logic or strategy i need,to make AI Run away from player,avoiding obstacles on its way and then when player is not in sight ai stops and switches to idle state...whatever. Like in video games when npc are in panic they just run away from player...

    Actually i have very good knowledge in NavMesh,i have made my ai scripts very good and smooth,but to make them run away in random direction or .......... duhhhhh

    HELP ME OUT SMART PEOPLE!
     
  2. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    Once the trigger is entered you can get the enemy location vector and the players location vector and subtract them, which would give you a vector pointing away from the player, for the enemy to travel.

    If you got a nav mesh system you could use that vector and a distance to find a location to solve a path for.
     
    Claymore likes this.
  3. Claymore

    Claymore

    Joined:
    Oct 17, 2012
    Posts:
    158
    Good idea,but how? i dont know,how to write that,anyways thanks for reply.
     
  4. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,541
    If you want stupid simple you could just do a negative look at then move it forward, dodging obstacles with ray wiskers. Or you could place a nav point in front of it.

    Sorry, that's just from my limited reading on pathfinding.
     
    Claymore likes this.
  5. Mark981

    Mark981

    Joined:
    Sep 20, 2012
    Posts:
    44
    Ohh,that is also a good idea,thank you.
     
  6. Claymore

    Claymore

    Joined:
    Oct 17, 2012
    Posts:
    158
    Naaa F*** You all son of a bitches.
     
    IgorAherne likes this.
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Not acceptable. Goodbye.

    --Eric
     
    justinsykes2006, lliviu and Not_Sure like this.
Thread Status:
Not open for further replies.