2 ms·
> Before anything on the scene is stepped, determine whether the character is standing on a moving platform. This can be done by checking, for example, whether
by deathanatos 11y ago
> Before anything on the scene is stepped, determine whether the character is standing on a moving platform. This can be done by checking, for example, whether his center-bottom pixel is just one pixel above the surface of the platform. If it is, store a handle to the platform and its current position inside the character.
I implemented a 2D platformer with moving platforms once; we solved this simply by using another rule in the article — the one for ladders:
> when you’re in a ladder, you ignore most of the standard collision system, and replace it with a new set of rules.
There was a special flag on the entity for "is on a platform" (and which platform, too); thus, you trivially knew if something was on the platform. During normal collision detection, if you found yourself falling through a platform, your fall was truncated, and you were affixed to the platform. (An entity's platform variable became, essentially, Some(a_ref_to_the_platform).) The affixing was two-way, IIRC: the platform knew about you, mainly s.t. when it moved, it could update linked entities. And if it was destroyed — which could happen — then it could unref itself from whatever was on it; really, one had a weakref to the other, but I was not that good a programmer then, so it was more manually implemented.
It worked quite well. We tried the whole pixel business, but it was troublesome; the game engine itself needed to deal with characters falling >1px per game state step, so it already knew "you are falling into a platform" bit.
- yoklov 11y agoI've kept a list of 'touching' entities (and where they are touching) on each entity before. Every frame this was cleared and rebuild as collision detection is performed. The moving platform's update code will then move any entity that was touching it's top. Having this list available was also handy for other gameplay too, so I'm a fan of this solution, even if it has some overhead.