Search Unity

AI Movement

Discussion in '2D' started by TofuMars, Mar 27, 2015.

  1. TofuMars

    TofuMars

    Joined:
    Oct 15, 2014
    Posts:
    3
    Hello, I am a beginner to Unity and was wondering about a few things. I am creating a 2D game at the moment, and wanted to create an AI for a monster I have where he would idle about and walk around. I don't want anyone to offer me a complete code to this and I am only asking for tips on how I could solve this. My idea is to make a rectangle for the range he would walk in, if he bumps into a wall, he would then create another boundary the size of his jump height to see if he can jump over the wall. The only problem is how I can get him to move. I checked out the charactercontroller section, and I think it is neat even though it is only for 3d. I want to know tips on how I can create this AI through the use of the physics controlled movement, and not resort to the use of an experimental version of charactercontroller2d. I just need tips or a simple example of AI movement so I could later on work on this wiht better understanding. I appreciate your time to respond :) .
     
  2. 016hnoor

    016hnoor

    Joined:
    Mar 27, 2015
    Posts:
    1
    I am creating a 2D game at the moment, and wanted to create an AI for a monster I have where he would idle about and walk around.

    I don't want anyone to offer me a complete code to this and I am only asking for tips on how I could solve this.


    _________________
    We offer best quality http://www.test-king.com/ test papers and dumps materials. You can get our 100% guaranteed questions pittstate to help you in passing the real exam of www.mica.edu
     
    Last edited: Apr 14, 2015
  3. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    There are assets on the Asset Store to help with this kind of thing.

    Your AI is separate from the method you use for movement as far as using the physics system or not.

    Basically your AI is just your code and data that determines the behavior of a virtual entity (enemy, friendly NPC, etc). The AI can be very simple or very complex depending on how much work you want to put into it.

    Your AI will determine when your virtual entity changes state such as transitioning from Idle to walking. Or walking to stopping. And so forth. Your AI manages these states and the triggers that cause the transition. The trigger can be as simple as the passing of time or distance moved. It can be more complex where your virtual entity actively scans the surrounding area and reacts to what it finds. For example, if walking and finding a wall a short distance ahead the entity may transition from walking to jumping. If the entity detects a threat (perhaps the player) it may transition to Fleeing state or it may transition to Attack state. How it determines which to do is up to you. It can be as simple as this particular entity always flees and this other entity always attacks. It can be as complex as this entity sizes you up determines it has a good chance to defeat you so attacks and when it is clearly losing the battle it decides to flee.

    All of these information gathering and reacting to the information routines are your AI. Figuring out how to behave. What to do and when to do it and for how long to continue. How you actually move the entity is a separate concern that comes after your AI has decided the enemy needs to move (or is currently moving).
     
  4. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    As far as actually implementing the mechanics of motion you would define a velocity for the entity. And you'll create the appropriate animations (walking, jumping). I don't use Unity physics but it is basically the same thing in the end. To move the entity right I would set its velocity to (1f, 0f). Using Unity physics you would Apply a force to move the entity in the same manner. When you detect the wall you would apply an upward velocity to lift the entity into the air and over the wall and let gravity pull the entity back to the ground. You'd just need to experiment with the amount of force being applied and the animation until you are satisfied with the result.
     
  5. TofuMars

    TofuMars

    Joined:
    Oct 15, 2014
    Posts:
    3
    Thank you so much! Appreciate the help.