seiyria Posted September 12, 2014 Share Posted September 12, 2014 So I have this object in my project that is "conditionally collidable" -- meaning it can only be collided with when it's in a certain frame of animation. See this gif: http://puu.sh/bvpa2/3e41598204.gif I only want to be able to collide with the block when it's solid... however, if it stops being solid while I'm on top of it, I want the collision to not happen (and consequently I should fall through it). Currently, this is what's happening: http://puu.sh/bvpgM/c521323df1.gif In arcade physics this was pretty simple, just specify a callback for if the collision should happen. I've been fighting with this for a while with p2 and I'm not certain how possible it is. Link to comment Share on other sites More sharing options...
valueerror Posted September 12, 2014 Share Posted September 12, 2014 this disables the collision of the block..vanishblock.body.data.shapes[0].sensor = true;now you just need to figure out when and how to trigger it.. if this is a standard animation i guess it would be the easiest way to just get the current animation frame and if its 0 for example then trigger the sensor.. otherwise go back to normal (sensor = false) http://docs.phaser.io/Phaser.Animation.html#frame Link to comment Share on other sites More sharing options...
wayfinder Posted September 12, 2014 Share Posted September 12, 2014 I don't think it's quite as easy as that - what happens if the sensor is turned solid while the player is still falling through it? The resulting separation force would probably shoot the player around the map. So you'll need at the very least a check for that. Link to comment Share on other sites More sharing options...
valueerror Posted September 12, 2014 Share Posted September 12, 2014 there you are totally right wayfinder.. this special case needs to be handled.. you should do an overlap check before enabling the collision again.. of course this is not that easy in p2 because there is no "overlap" function present.. Link to comment Share on other sites More sharing options...
valueerror Posted September 12, 2014 Share Posted September 12, 2014 well.. this is probably an overkill but you could cycle through the presolve equations to find out if your player is going to collide in this step and if so - don't allow enabling the collision again (if it isn't already enabled)function onPresolve(presolve){ for (var i = 0; i < presolve.contactEquations.length; i++) { c = presolve.contactEquations[i] f = presolve.frictionEquations[i]; allowCollisionEnabling = true; if (c.bodyA.parent.sprite && c.bodyA.parent.sprite.name === 'myplayer'){ //define here who is allowed to stop the activation of the collision if (c.bodyB.parent.sprite && c.bodyB.parent.sprite.name == 'vanishplatform'){ // check for jumpthrough object allowCollisionEnabling = false; return; //don't go further - otherwise it would allow it agoin } } }} Link to comment Share on other sites More sharing options...
wayfinder Posted September 12, 2014 Share Posted September 12, 2014 since 2.1.0 there actually IS an overlap function Link to comment Share on other sites More sharing options...
seiyria Posted September 12, 2014 Author Share Posted September 12, 2014 since 2.1.0 there actually IS an overlap function Great! I'm not certain I'll need it, since on average, players will fall through pretty quickly. I'll have to try it out and see how it works.. if it pushes them too far / too fast then I'll work around it. this disables the collision of the block..vanishblock.body.data.shapes[0].sensor = true;now you just need to figure out when and how to trigger it.. if this is a standard animation i guess it would be the easiest way to just get the current animation frame and if its 0 for example then trigger the sensor.. otherwise go back to normal (sensor = false) http://docs.phaser.io/Phaser.Animation.html#frameThanks for this! Seems simple enough, I just wasn't sure what I should be toggling.. P2 has a lot of stuff in it after all. Link to comment Share on other sites More sharing options...
valueerror Posted September 12, 2014 Share Posted September 12, 2014 @seiyria: there is another exeption where this could be a problem and demands a workaround.. if you are just jumping on the block and it is not completely solid yet.. or you jump through from below and it gets solid while you are in it.. @wayfinder.. what?? thats awesome.. where is it hidden.. (going to seach for it right now ) Link to comment Share on other sites More sharing options...
wayfinder Posted September 12, 2014 Share Posted September 12, 2014 body.overlaps Link to comment Share on other sites More sharing options...
seiyria Posted September 13, 2014 Author Share Posted September 13, 2014 Here is the solution I ended up going with: disappear: -> @body.data.shapes[0].sensor = yes @currentAnim = @animations.play 'fade' if @auto @currentAnim = @animations.play 'fade_once' if not @auto @currentAnim.enableUpdate = yes @currentAnim.onUpdate.add (e) => @body.data.shapes[0].sensor = e._frames[e._frameIndex] isnt 0 @currentAnim.onComplete.add => @body.data.shapes[0].sensor = noset the sensor, update sensor every frame based on the actual frame, and when complete, turn collision back on. Thanks for the help all! Link to comment Share on other sites More sharing options...
Recommended Posts