How do i make an 2D AI wander?

Im working on a dungeon crawler type game and I already have the monsters be able to move towards the character, but I also want the enemies to wander and move around on their own. How do I do that? Also how do I make enemies not be able to see through walls?

Comments

  • bob loblawbob loblaw Member, PRO Posts: 793

    depends what kind of wandering you want them to do.

    if you want a sentry type movement going left and right, you can use a simple set of logic that says if the actor’s x >= a position on the screen, change the velocity to the opposite of what they’re doing.

    if you want something more complex, like movement in x and y axis, you could use anchor points that tell the actor to change its movement based on the anchor, as well as maybe calculating a shortest path if attacking another actor.

  • student0438_ecisd_usstudent0438_ecisd_us Member, PRO Posts: 5

    @bob loblaw said:
    depends what kind of wandering you want them to do.

    if you want a sentry type movement going left and right, you can use a simple set of logic that says if the actor’s x >= a position on the screen, change the velocity to the opposite of what they’re doing.

    if you want something more complex, like movement in x and y axis, you could use anchor points that tell the actor to change its movement based on the anchor, as well as maybe calculating a shortest path if attacking another actor.

    The type of wandering I want is that they would move up, down, left, right without a specific path.

  • adent42adent42 Key Master, Head Chef, Executive Chef, Member, PRO Posts: 3,159

    If you are spawning your levels based on a table, you could use that table as the basis of A* pathfinding and have your actor patrol two waypoints. The only bad thing is you'd need a separate copy of the level table for each patrol actor, but it might be worth it for any actor not patrolling in a straight line.

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    edited February 2020

    @student0438_ecisd_us, here is a video I did about using way points, similar to what @bob loblaw mentions above.

  • student0438_ecisd_usstudent0438_ecisd_us Member, PRO Posts: 5

    @jamie_c said:
    @student0438_ecisd_us, here is a video I did about using way points, similar to what @bob loblaw mentions above.

    Thank you, can you send me the video you mentioned within the video too? Also if know how to add Knock back on an enemy, such as "if enemy collides with player then" do a knock back action, can you send me a video or explain it. Please and Thank You for this information

  • bob loblawbob loblaw Member, PRO Posts: 793
    edited February 2020

    @student0438_ecisd_us said:

    @bob loblaw said:
    depends what kind of wandering you want them to do.

    if you want a sentry type movement going left and right, you can use a simple set of logic that says if the actor’s x >= a position on the screen, change the velocity to the opposite of what they’re doing.

    if you want something more complex, like movement in x and y axis, you could use anchor points that tell the actor to change its movement based on the anchor, as well as maybe calculating a shortest path if attacking another actor.

    The type of wandering I want is that they would move up, down, left, right without a specific path.

    @jamie_c ‘s video is a good one to learn some ground work from.

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    @student0438_ecisd_us, the other two videos in this series were:

    You can find lots more at my youtube page if you're interested.

    As far as a 'knock back' action goes I don't specifically have a tutorial for that. But it sounds like you've got the concept figured out already. Use a Rule to test if the player and enemy have collided and when the do use a behavior to 'knock back' the enemy.

Sign In or Register to comment.