Line of sight with platformer enemy

0 favourites
  • 5 posts
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • Hi everyone,

    I'm building a side-scrolling platform game and I need to create enemies with a little AI.

    Enemies has the platform behavior and they are meant to follow the player and once they are close enough firing at him (simple as that).

    For now the code is someting like this:

    For Each Enemy  {
       >  Has line of sight to Player
             >  Is close enough  
                  >  Fire 
             >  Else
                 > Is at Player's left
                        >  Simulate platform pressing Right
                 > Else
                        >  Simulate platform pressing Left
       >  NOT has line of sight to Player
           >  Rest
    }  
    [/code:2fllszec]
    
    In the [b]level maps[/b] there are [b]little holes to jump[/b] and [b]Solid blocks to "climb"[/b] [i](actually you just jump over them)[/i].
    
    My problem now is that I don't know how to "[b]teach[/b]" enemies to [b]jump[/b], because the move correctly, but when there's an hole in the ground and the player jumps it, they just keep walking and fall.
    Is there a method in LineOfSight, or similar, to let them know that they can also [b]jump [/b]holes and/or little solid blocks?
    
    [b]Thanks to everyone in advance.[/b]
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hello mci!

    I think there are several possibilities to solve your problem. I think the best could be to place some kind of invisible landmark just before the hole. When one of your enemy gets in collision with the landmark, he jumps. You could even make the jump according to some specific values saved in some instance variables of the landmark. This way the enemy would jump more or less depending on the size of the following hole.

    Hope this is relevant!

  • Thank you very much GAMAN, brilliant idea.

  • You're welcome! Glad it helped.

  • Rather than placing a landmark at each ledge, consider adding an invisible sprite attached to the lower front of your actor to detect ledges. Place it below the bottom edge and set it's position (or pin if you prefer, I tend not to use pin as much) relative to your actor. When the detector is no longer overlapping a floor, it means a hole is directly in front. Similarly, you can set a detector above at max jump height. If the actor reaches a wall, and the detector is not overlapping the wall, the actor could jump instead of turning around.

    Using detectors on your actors is a great way to build logic without using too many objects all over your levels.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)