megmut Posted April 14, 2016 Share Posted April 14, 2016 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 More sharing options...
drhayes Posted April 14, 2016 Share Posted April 14, 2016 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. WombatTurkey and Tom Atom 2 Link to comment Share on other sites More sharing options...
megmut Posted April 14, 2016 Author Share Posted April 14, 2016 @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 More sharing options...
lewster32 Posted April 15, 2016 Share Posted April 15, 2016 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. drhayes 1 Link to comment Share on other sites More sharing options...
Recommended Posts