Jump to content

Different gravities for different objects

Recommended Posts


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

    game.physics.p2.gravity.y = 100;
    this.car = game.add.sprite(32, 32, "car");
    this.car.body.windResistance = 0.4;

    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 post
Share on other sites

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


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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...