schteppe / p2.js

JavaScript 2D physics library
Other
2.63k stars 330 forks source link

[bug] new body's previousPosition is [0,0] #335

Closed Fxlr8 closed 5 years ago

Fxlr8 commented 5 years ago

Hi, I am making a game, in which a moving player can shoot projectiles. I use fixed time stepping with interpolation for my world. Projectiles are just circles with mass=0.09 and radius=10. They are added to the world in a postStep event handler with player's position and some velocity.

this.world.addBody(new Fireball({
    mass: 0.1,
    position: [player.position[0], player.position[1]],
    velocity: [player.velocity[0] + vx, player.velocity[1] + vy] 
}))

When they are added, their previousPosition appears to be [0, 0], when their current position is like [1000, 1200].

for example:

previousPosition [ 0, 0 ]
position [ 1268.4556884765625, 3930.0595703125 ]
interpolatedPosition [ 359.11944580078125, 1112.66064453125 ]

This makes p2.js interpolate it from [0, 0], which has no sence, and an object makes an ugly jump for one frame.

Fxlr8 commented 5 years ago

Actually, looks like this problem was already solved by https://github.com/schteppe/p2.js/commit/0b33d985d903d44a946616ecd116a58fc538c490 3 years ago. Please, publish updates to npm

schteppe commented 5 years ago

Will publish a release to npm when the latest code has been tested enough. If you need this fix right now, point your package.json directly to github.