Jump to content

Using Tweens with P2 Physics bodies


GameDemon
 Share

Recommended Posts

Is there a guide for using tweens/easing with P2 physics bodies?

 

I tried using body.x like so:

var tween = game.add.tween(jar.body).to( { x: 384 }, 2000, Phaser.Easing.Linear.Out, true);

It works, but there's a risk of tunneling with fast movement - do I need to call some kind of update function? 

 

Alternatively I tried using body.velocity:

var tween = game.add.tween(jar.body.velocity).to( { x: 384 }, 2000, Phaser.Easing.Linear.Out, true);

This works better it seems, but how do I make movements to precise coordinates onscreen?

Link to comment
Share on other sites

Hi thanks for your reply. The reason i need both tweens and physics is because I'm creating an animation where some elements behave in a physics-based way (gravity/collisions) while with the others I want the fine control of tweens. So for instance, I want to move a container body around the screen to exact positions with easing equations, and then also have the contents of this container (a load of ball-shaped bodies) being jostled around by physics.

 

I thought that using the kinematic setting on the tweened body should be able to do this, but i was experiencing the issues I mentioned.

Link to comment
Share on other sites

Here's a demo:

https://output.jsbin.com/hopufu/2

 

Here I slide the jar-shaped kinematic body offscreen with a tween (click red button to start) - the ball bodies seem to go crazy at some point and also you might notice that some of them start to overlap the polygon shape - if I use a fast tween they can tunnel through.

 

If I tween the body.velocity.x value it doesn't exhibit these issues, but then I can't move the bodies to exact x/y coordinates. Thanks if you have any ideas!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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