Line of sight with platformer enemy

Discuss game development design and post your game ideas

Post » Tue Mar 08, 2016 1:46 pm

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:
Code: Select all
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



In the level maps there are little holes to jump and Solid blocks to "climb" (actually you just jump over them).

My problem now is that I don't know how to "teach" enemies to jump, 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 jump holes and/or little solid blocks?

Thanks to everyone in advance.
B
4
Posts: 5
Reputation: 210

Post » Tue Mar 08, 2016 2:18 pm

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!
Last edited by Bro7hers on Tue Mar 08, 2016 4:53 pm, edited 1 time in total.
Image
B
10
S
3
G
2
Posts: 81
Reputation: 1,735

Post » Tue Mar 08, 2016 3:15 pm

Thank you very much @GaMan, brilliant idea.
B
4
Posts: 5
Reputation: 210

Post » Tue Mar 08, 2016 4:50 pm

You're welcome! Glad it helped. :)
Image
B
10
S
3
G
2
Posts: 81
Reputation: 1,735

Post » Mon Mar 28, 2016 10:55 am

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.
B
17
S
7
Posts: 21
Reputation: 1,711


Return to Game Development, Design & Ideas

Who is online

Users browsing this forum: No registered users and 1 guest