- Home /
2D Platformer Moving Platform Question
So I'm making a 2D platformer for iPhone, and I have some moving platforms here and there. The way I've implemented moving platforms is by adding a trigger on top of the platform (Making the trigger have slightly less width than the platform so a character shouldn't get stuck on the platform), and OnTriggerEnter the player will be parented to the platform. It works beautifully until I realized that if the player misses the platform slightly while the platform is moving towards him, the player moves inside the platform and the game starts glitching o.O
I think the solution may have something to do with Rigidbodies, so that the platform will push the player aside as opposed to having the player pushed into the platform. However, rigidbodies caused even more glitches (the player model would scale way up, and the platform will start spinning everywhere.
Any help would be greatly appreciated.
the platforms don't need rigid bodies, rigid bodies are only for simulating physics and seeing as floating platforms have very little to do with physics you should just use solid colliders.
What you can do is make the trigger much taller than the platform and then when the player enters the trigger have the player's local y position snap to the surface of the platform. This will stop the player missing the trigger and also stops floating players. Unparenting when the player exits the trigger will be fine.
@spinaljack - Actually, I believe the problem does has something to do with physics. I don't think I'm being very clear :-. Okay, what I mean is...let's say you've got a moving platform (shaped like a cube). There is a trigger on top of the cube that parents the player to that cube. That handles the player moving with the platform, and that works fine. The problem arises when the player collides not with the TOP of the platform, but with one of the sides of the platform. If that happens, and the platform is moving towards player, then it will not move the player with it. The player will just
get stuck on the side of the platform, and slowly get...consumed lol.
Answer by Archangel3d · Jan 13, 2011 at 03:32 PM
You could "fudge" it so that when your character sets off the OnTriggerEnter, the script matches the character's root Y position (at his feet) to the platform's Y position, causing him to "blink" high enough to be standing on the platform.
Answer by runevision · Jan 13, 2011 at 03:55 PM
For something like a moving platform you should use a Kinematic Rigidbody - i.e. a Rigidbody with isKinematic set to true.
NEVER move an object with a Static Collider (= no Rigidbody or CharacterController) and certainly not on a per-frame basis! It both has a massive performance penalty and doesn't work correctly together with other Rigidbodies.
Your answer
Follow this Question
Related Questions
2.5D platformer main character collision 1 Answer
How to trigger a Moving Platform with a collider? 2 Answers
Moving character on a moving ground 1 Answer
Help Needed with Blender animations 4 Answers
Moving character to a specific point ? 0 Answers