4ian / GDevelop

🎮 Open-source, cross-platform 2D/3D/multiplayer game engine designed for everyone.
https://gdevelop.io
Other
10.83k stars 849 forks source link

[Platformer] Add a condition to pick the current floor #3029

Closed D8H closed 3 years ago

D8H commented 3 years ago

Description

It's complicated to detect on which platform the character is. https://github.com/4ian/GDevelop/issues/1920

Solution suggested

I think a condition like: "PARAM0 is on PARAM2" could help building platformer events extensions. For instance, a behavior that makes the character follows a moving platform when he's jumping from it.

4ian commented 3 years ago

@D8H: @AlexandreSi will take a look at this :) And I hope we can bundle this in a testing version containing #3009, so we can get users to test this! :)

A few notes on this.

This is not an usual condition in the sense that this condition will "pick" two kind of objects: the floor and the platformer objects. For example, the condition "Player is on Platform" should pick:

For example, if we have 3 instances of Player (Player #1, Player #2 and Player #3) and 2 instances of Platform (Platform #1, Platform #2 and Platform #3), and we imagine that Player 1 is on Platform 1, Player 2 is on Platform 2, on Player 3 is not on any platform (and so Platform 3 is not the floor of anything), this means the condition must pick:

This sounds maybe obvious, but if we add this condition naively as a behavior condition, with an implementation like this:

isOnFloor(candidates: Hashtable<Array<gdjs.RuntimeObject>>) {
  // return true if the current floor is inside candidates
}

then the filtering of objects will be done only on Player (i.e: the object having the behavior). And so all platforms will be considered for future actions (which is not right, if we have a condition like this, we only want to launch actions on platforms that are effectively a floor of a Player).

So this is a condition filtering N objects of a list with M other objects of another list. In other words, it must be implemented with gdjs.evtTools.object.twoListsTest. This function launches a predicate on each pair of these N and M objects.

This also means that this condition must be a "free condition", outside of the Platformer behavior. In a sense, it's normal because it uses two behaviors! You can get inspired by gdjs.physics2.objectsCollide.