Jump to content

Physics Tween Alternative???


megmut
 Share

Recommended Posts

Hey guys, I'm stuck with this one.. I've just started getting into Physics now and I need to 'tween' an object from position 1, to position 2.

When not using physics, I could simply do.. 

this.game.add.tween(this.player).to({x: 150, y: 250}, 250, Phaser.Easing.Quadratic.InOut, true);

Now I know I can't move the x and y of an object when physics is applied as you're only moving the topographical view, and the body itself isn't moving.. so I'd guess I need to accelerate the body to a mid point, then decelerate to stop on the correct posX and posY.

Are there features in Phaser to achieve this, or do will I have to write these myself?

Thanks, Nick

Link to comment
Share on other sites

I believe this is what the "body.moves" property is for. Set it to false and the physics system will leave the body alone until you set it to true again. That way you can use a tween instead of doing the calculations yourself.

Even if you did the calculations yourself I wouldn't trust the fidelity of a physics system to get that object to precisely where you wanted it.

Link to comment
Share on other sites

@drhayes thanks for the reply! Hmm, when the body.moves is set to false, will physic collisions still occur, or not until body.moves is enabled again?

I'm quite surprised I haven't found more information on this!

Thanks

Nick

Link to comment
Share on other sites

Physics collisions will still occur, however because your object is being tweened, the collisions will not affect its position, only the positions of other non-tweened objects colliding with it. Think about this in real world settings - if you could move something infinitely strong with infinite force (such as how a tween on an object does) then how would it act? If instead you want to move the object via physics, then you have to accept that this must be done with finite, calculated forces, like playing pool for instance. There's no real way to reconcile the absolute nature of tweens with the relative force-directed nature of physics, and if both are being used together tweens will always win in the end.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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