GameDemon Posted August 5, 2015 Share Posted August 5, 2015 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 More sharing options...
tips4design Posted August 5, 2015 Share Posted August 5, 2015 I usually only use tweens on elements that do not have physics enabled or them (or do the tween before enabling the physics). Why do you need both physics and the ability to set an objects position in a tween? They are most likely to conflict. Link to comment Share on other sites More sharing options...
GameDemon Posted August 6, 2015 Author Share Posted August 6, 2015 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 More sharing options...
tips4design Posted August 6, 2015 Share Posted August 6, 2015 Hmm, it should work with a kinematic body. Can you post a fiddle link or some more code? Link to comment Share on other sites More sharing options...
GameDemon Posted August 6, 2015 Author Share Posted August 6, 2015 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 More sharing options...
Recommended Posts