Jump to content

Different gravities for different objects


Bartuken
 Share

Recommended Posts

Hello!

In Phaser ( particularly Phaser CE ) I can't find something like Wind Resistance for objects. And start thinking how to implement my own version:

  create(){
    game.physics.startSystem(Phaser.Physics.P2JS);
    game.physics.p2.gravity.y = 100;
    
    this.car = game.add.sprite(32, 32, "car");
    game.physics.p2.enable(this.car,false);
    this.car.body.windResistance = 0.4;
  }

  update(){
    if(this.car.body.windResistance && this.car.body.velocity.y > this.car.body.windResistance ){
      this.car.body.velocity.y-= this.car.body.windResistance;
    }
  }

With this I can't use big numbers for windResistance, only between 0 and 1.

What do you guys think??

Link to comment
Share on other sites

For different gravities, you can set gravity scale on each sprite:

https://phaser.io/examples/v2/p2-physics/gravity-scale

You can use the damping property to introduce drag/windresistance on each sprite.
You can use values higher than one if your looking for a threshold value for velocity. But if you subtract the same number in update things might go wrong. Also the if statement does not look like it will work. 
 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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