nomolosvulgaris Posted July 24, 2014 Share Posted July 24, 2014 I'm developing an arcade game (2d platformer) with enemies moving like this:http://codepen.io/anon/pen/FytIg?editors=011Everything looks fine, but the enemy tends to fall down when the ledge is too short for completing enemy's way (you can see what I mean by uncommenting the only commented line in my code). It's not what I want. So I find a way to bind a callback on the "moves-to-the-edge" event. Maybe to figure out if the collision with ground is only partial. This event might also be helpful to activate a "panic animation" for player staying at the edge (like in Sonic The Hedgehog). How can I do this? The only solution I can think out is to wrap the enemy with invisible bodies to check whether they are blocked from down on each step. But is this the only solution? Link to comment Share on other sites More sharing options...
lewster32 Posted July 24, 2014 Share Posted July 24, 2014 This 'edge of platform detection' has been covered a few times, so I'll direct you to the relevant posts where the discussion takes place:http://www.html5gamedevs.com/topic/7942-interesting-phenomenon-with-platformer-cliff-detection/http://www.html5gamedevs.com/topic/7922-enemy-sense-the-end-of-the-floor/The basic options are either to have some way of detecting the edges dynamically, or putting invisible markers or 'bumpers' at the edges of each platform which turn enemies around before they fall off. Camps are divided over which method is best, but it depends entirely on the game you're making. Link to comment Share on other sites More sharing options...
Recommended Posts