Jump to content

Change collision status while standing on target body


seiyria
 Share

Recommended Posts

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

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

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

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

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. :D

 

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

Thanks 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

@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

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 = no

set 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

 Share

  • Recently Browsing   0 members

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