Jump to content

I dont want the player to move with platform


bru
 Share

Recommended Posts

Hello,

 

i have a movable platform, right now when the player is on it he move with it but i dont want that, i want him to fall when the platform go away, is there any way to do this ? (I use Phaser v2.0.3)

create: function{        // the Player        this.player = this.game.add.sprite(100, 30, 'yellow');        this.game.physics.enable(this.player, Phaser.Physics.ARCADE);        this.player.body.collideWorldBounds = false;        this.player.body.setSize(50, 50, 0, 0);        this.player.body.gravity.y = 2600;        // platform        this.platforms = this.game.add.group();        this.platform = this.platforms.create(0, this.game.height-100, 'brick');        this.platform.anchor.setTo(0, 1);        this.platform.scale.setTo(30, 1);        game.physics.enable(this.platform, Phaser.Physics.ARCADE);        this.platform.body.immovable = true;     }update: function{        this.game.physics.arcade.collide(this.player, this.platforms);             // moving the platform        this.platform.body.velocity.x = -500;}

if tried to add this :

if(this.player.body.touching.down){   this.player.body.velocity.x = 500;}

but is very bad because i want the player to stay on the exact same horizontal position all the game and with this he go on the right.

 

any idea ?

 

 

ps: this is my first post here so i take the opportunity for thank the phaser team :)

ps2: sorry for my english i am not native

Link to comment
Share on other sites

hehe.. when i created my first moveable platform the player did exactly what you want... it took me some time to get the player to move with the platform.. i think there ate 2 ways to do that....

first.. don't use velocity just chsnge the x position

platform.body.x += 10; for example

second you could define materials and give the platform something with zero friction.. the player should slide of the platform

Link to comment
Share on other sites

"it took me some time to get the player to move with the platform.."

Yes i saw some topics about this :)

platform.body.x += 10;

Only this did the trick, thank you very much :unsure:

Link to comment
Share on other sites

But this comes with another problem, the physics engine seams to ignore horizontal collisions when moving objects directly.

Any way of fixing that? Now my character no longer gets pushed back when an object hits it.

Link to comment
Share on other sites

http://test.xapient.net/phaser/movingplatform-m.html  here is an old example where i realized the movement with tweens.. i tweened the x-coordinate therefore there are no collisions and the player stands still on his placein the world..

 

@aealo:  i don't see a problem here..  i don't move the player directly, just the platform..  and the player still collides with the platform on its sides..  you need to set the moving object to "kinematic"

platformH = game.add.sprite(300, 200, 'platform');game.physics.p2.enable(platformH);platformH.body.kinematic=true;platformH.body.setMaterial(groundMaterial);game.add.tween(platformH.body).to({ x: '+100' }, 2000,Phaser.Easing.Linear.None).to({x:'-100'}, 2000,Phaser.Easing.Linear.None).yoyo().loop().start();
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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