Jump to content

How to create a moving Platform to jump on with P2


valueerror
 Share

Recommended Posts

right now THIS is my approach:

 

global:

var platformvelocity1=100;

create:

movingplatformvertical = game.add.sprite(150,  game.world.height - 300, 'paddle'); game.physics.p2.enable(movingplatformvertical);movingplatformvertical.body.setCollisionGroup(groundCG);movingplatformvertical.body.collides(playerCG);movingplatformvertical.body.mass=9999;movingplatformvertical.body.data.gravityScale=0;movingplatformvertical.body.data.motionState =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: http://test.xapient.net/phaser/ALL/

 

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 !!

Link to comment
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.

Link to comment
Share on other sites

  • 5 months later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...