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.
asked Jul 09 '10 at 04:11 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.
answered Jan 13 '11 at 03:32 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.
answered Jan 13 '11 at 03:55 PM