How to create a moving Platform to jump on with P2

Recommended Posts

right now THIS is my approach:



var platformvelocity1=100;


movingplatformvertical = game.add.sprite(150, - 300, 'paddle'); game.physics.p2.enable(movingplatformvertical);movingplatformvertical.body.setCollisionGroup(groundCG);movingplatformvertical.body.collides(playerCG);movingplatformvertical.body.mass=9999;; =1;movingplatformvertical.body.fixedRotation=true;

that means.. create plattform, activate physics, setup collisons, make it waay heavier than the player so the player mass wont affect it, make it immune to gravity, set it to dynamic, disable rotation


and then in the update loop:

if(movingplatformvertical.body.y  > 800){ platformvelocity1*=-1;}else if (movingplatformvertical.body.y < 600){platformvelocity1*=-1;}movingplatformvertical.body.velocity.y =platformvelocity1;movingplatformvertical.body.x = 150;  //make x static

you may test it here:


this looks very improvised and i can not get rid of the feeling that there is a MUCH better, easier way for this - so if you have some insight - please feed me your information.. thank you all very much !!

Share this post

Link to post
Share on other sites

Whoa, that's a LOT of mass! You should really use a kinematic body for the platform, not dynamic. And probably a material that stops the player sliding off it, something with a low surface velocity.


I'll put together an example showing this next week.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.