# 2D Platformer Moving Platform Question

 0 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. more ▼ asked Jul 09 '10 at 04:11 PM Kith 541 ● 27 ● 28 ● 38 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. Jul 09 '10 at 04:15 PM spinaljack 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. Jul 09 '10 at 04:17 PM spinaljack @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 Jul 09 '10 at 04:24 PM Kith get stuck on the side of the platform, and slowly get...consumed lol. Jul 09 '10 at 04:26 PM Kith add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 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. more ▼ answered Jan 13 '11 at 03:32 PM Archangel3d 36 ● 2 ● 2 ● 6 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 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. more ▼ answered Jan 13 '11 at 03:55 PM runevision ♦♦ 8.1k ● 29 ● 46 ● 112 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x1081
x213
x192
x70
x37

asked: Jul 09 '10 at 04:11 PM

Seen: 2812 times

Last Updated: Jul 09 '10 at 04:11 PM