Search Unity

Is there a way to create a path for an AI character to follow in a 2D game?

Discussion in '2D' started by AcidicPaper, Dec 28, 2015.

  1. AcidicPaper

    AcidicPaper

    Joined:
    Feb 11, 2015
    Posts:
    12
    Hello!

    My name is Dean. I'm currently working on a 2D, puzzle game where the SkullPrincess (you) has to rescue her butlers, maids etc from imprisonment in random shapes.

    I'm finding it hard to find where I can create a pathway for the AI to follow, whilst imprisoned. Hence why i've come to this forum.

    (please bare with me as well. I apologise if my language isn't 'technical', I'm very new to the Unity software.)

    Screen Shot 2015-12-28 at 20.58.12.png

    This is initially, the game scene. The star will be the compound where the little fella on the left will be awaiting freedom.

    Screen Shot 2015-12-28 at 20.58.19.png

    Here's the little fella up close. He has a NAV MESH AGENT attached to him (I assumed that with this agent it would automatically produce a mesh or path in which the fella could travel on, I was wrong).

    Screen Shot 2015-12-28 at 20.58.25.jpg

    And finally, the mechanic I intend to be able to let the player use once the game is ready.

    Blue lines indicate non walkable areas (basically if the path is more than 90 degrees to the current location of the fella, then they can't walk there).

    Red lines means the opposite. The little fella can walk here.

    Green indicates interaction by the player to manipulate the wall. By the player dragging the assigned segment down, they are then able to change the path the little fella can walk on. Ultimately this leads the little fella to the white box, which in game will represent where the player needs to guide the little fella in order to win and proceed to the next level.

    What I really need help with, is finding out how to generate this pathfinding in a 2D game. As well as being able to manipulate certain parts of an asset (the star, for example) to proceed on in the game.

    Many thanks guys. I hope that was okay for you. :)
     
  2. AcidicPaper

    AcidicPaper

    Joined:
    Feb 11, 2015
    Posts:
    12
  3. jamius19

    jamius19

    Joined:
    Mar 30, 2015
    Posts:
    96
    Explain it first :)
     
  4. AcidicPaper

    AcidicPaper

    Joined:
    Feb 11, 2015
    Posts:
    12
    how do you mean explain it?
     
  5. jamius19

    jamius19

    Joined:
    Mar 30, 2015
    Posts:
    96
    The blue line isn't more than 90 degrees from thr current position of the player :)
     
  6. AcidicPaper

    AcidicPaper

    Joined:
    Feb 11, 2015
    Posts:
    12
    Ah, I see what you mean. Basically, logically speaking the AI can't access that part of the shape because it's angle isn't accessible. It's not too important to go into.

    What I really want to work out is how I can make the AI navigate on the two angles highlighted in Red, navigating back and forth until the player manipulates part of the shape to make the exit accessible. :)
     
  7. jamius19

    jamius19

    Joined:
    Mar 30, 2015
    Posts:
    96
    Where is your enemy? :confused:
     
  8. AcidicPaper

    AcidicPaper

    Joined:
    Feb 11, 2015
    Posts:
    12
    I'm sorry, enemy? i didn't mention enemy. Do you even know what I'm trying to do?
     
    jamius19 likes this.
  9. jamius19

    jamius19

    Joined:
    Mar 30, 2015
    Posts:
    96
    My question is quite same. :)
    Have you studied when and where NavMesh Agent is used?

    And for the AI, where you wanna apply AI(Navigation System) to?
    To the PLAYER?