# Box2D Platform body not moving player body along with it

I am creating a game using Box2D (Javascript implementation) - and I added the ability to have a static platform, that is moved along an axis as a function of a sine.

My problem is when the player lands on the platform, as the platform moves along the X axis - the player is not moved along with it, as you visually would expect.

The player can land on the object, and if it hits the side of the object, it does colide with it and is pushed.

This image might explain better than I did:
After jumping on to the red platform the player character will fall off as the platform moves to the right

UPDATE:
Here is a live demo showing the problem:
http://onedayitwillmake.com/ChuClone/slideexample.php

• Do both surfaces have some amount of friction? Commented Jul 22, 2011 at 3:07
• How do you move the platform? Is there any chance to use a joint?
– Den
Commented Jul 22, 2011 at 8:13
• Well that is kind of the normal physical behavior. When the player jumps, give him also an impulse into the direction, where the platform moves to. Don't let him just fall onto the platform. Commented Jul 22, 2011 at 9:20
• If you jump from a bridge and land on a moving truck, the same will happen. Don't try it at home :p Commented Jul 22, 2011 at 9:22
• @Joe: Thanks for the clarification! I do still worry about whether being designated as 'static' is what's causing its movement not to be working as expected. Commented Jul 22, 2011 at 11:03

I move the platform by calling SetPosition on the body

I think this is the problem. Box2D is not designed to be used this way. Is there any way you can simulate sine function movement by applying impulses/forces?

• I've also tried using b2_KinematicBody instead, which as I understand it are made to be used that way, but the results were the same :( Commented Jul 22, 2011 at 16:14
• Is creating a joint dynamically (every time you land on platform) an option?
– Den
Commented Jul 22, 2011 at 16:17
• Reason why this doesn't work: SetPosition is like teleporting something. It's not going to bring anything with it: it won't move anything along with it because it's not moving, it won't apply any force on anything because it has no force being exerted on it to transfer - it's just going to flick out of existence here and back into existence there. Commented Jul 22, 2011 at 23:31
• @Jonathan - Yeah it's one of those things that makes sense / sounds obvious now that I know about it. Thanks for the good info :) Commented Jul 22, 2011 at 23:51

Solved!

For future people: The solution was to use b2_Kinematic bodies. Do not move it by calling SetPosition on the platform.

Call SetLinearVelocity, and then any body's "on top" will interact as you would expect.

Giving the answer credit to Den since he provided information that led me in the right direction.