Jump to content

P2JS Velocity and PointProxy / InversePointProxy


plasticrake
 Share

Recommended Posts

I'm new to Phaser, been playing with it the past few days.
 
I noticed odd behavior when setting velocity in P2.
 
This would not work as expected:

bullet.body.velocity.x = this.sprite.body.velocity.x;bullet.body.velocity.y = this.sprite.body.velocity.y;

After searching through the source I noticed that P2 converts the values from px to "meters" when setting the velocity, however it does not convert back to px when retrieving them. This happens in InversePointProxy for velocity, but properties using PointProxy would have the same issue as well.

 

I was able to fix it temporarily with this code:

bullet.body.velocity.x = this.sprite.body.velocity.x * -20;bullet.body.velocity.y = this.sprite.body.velocity.y * -20;

I tried to update the phaser source files to do the conversion both ways so I wouldn't need to do this, but this seemed to cause other issues when running my game. I updated both InversePointProxy and PointProxy.

 

Is this behavior by design? Here is an example of the change I made, Added this.world.mpxi() to the get.:

    get: function () {        return this.world.mpxi(this.destination[0]);    },    set: function (value) {        this.destination[0] = this.world.pxmi(value);    }
Link to comment
Share on other sites

  • 1 month later...

This post just fixed an issue i was trying to figure out for the past two days. 

 

I just completed javascript, html, css and JQuery tracks on codecademy and dove right into Phaser and P2 still very new to programming. Thank you, for posting this fix!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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