lonelydatum Posted June 23, 2014 Share Posted June 23, 2014 Hello, I have 2 floors, one above the other. What is the best way to have the player move between the the floors? For example when the down key is pressed I'd like the player to move to the floor below. Likewise when the up key is pressed I'd like the player to move to the floor above. Please see attached image. I was thinking about disabling/enabling the floor. If this is the best approach how do I this using Phaser?Thanks,Gar Link to comment Share on other sites More sharing options...
lewster32 Posted June 23, 2014 Share Posted June 23, 2014 It's a bit of a tricky one because if done wrong it could allow players to fall through walls etc. I'd probably do this with a tween rather than physics; when the player attempts to change track, check see if the player.body.blocked.down is true and that the player can move to the desired track, and if so, temporarily set player.body.moves = false; tween the player.y down or up by a value which will get it to the required ledge, then on the tween end restore player.body.moves to true and let physics take over again. There are probably cleverer and less hacky ways to do this, but this will work. Link to comment Share on other sites More sharing options...
valueerror Posted June 23, 2014 Share Posted June 23, 2014 can't you just tween between them? Link to comment Share on other sites More sharing options...
Heppell08 Posted June 23, 2014 Share Posted June 23, 2014 Depending on the setup of the tracks i would map the Y position at the lowest part of a track and a highest part of a track. Use a statement inbetween them values, check the body blocked, key down events etc, then just drop through the floor with either or tween or temporarily set the body blocked to false and drop through or up as and when required. Link to comment Share on other sites More sharing options...
lonelydatum Posted June 27, 2014 Author Share Posted June 27, 2014 Thanks @lewster32, @valueerror and @Heppell08 for the suggestions. I actually tried the tween but I found that it didn't look very realistic without the physics. Especially when the player is running and jumping/dropping to different tracks. I forgot to mention that I'm using P2 instead of ARCADE but I think I'm going to try refactor to ARCADE to compare. So I did eventually get the floor to disable/enable using this (if someone has a better way let me know):REMOVE BODY: floorTop.body.world.removeBody(floorTop.body);ADD BODY: floorTop.body.world.addBody(floorTop.body); Overall, to get the look and feel I wanted was really complicated. But if anyone is having the same problem I can share the code. Link to comment Share on other sites More sharing options...
valueerror Posted June 27, 2014 Share Posted June 27, 2014 in p2 you can deactivate collisions for the floor like this:floor.body.data.shapes[0].sensor = true;everything will stay the same but the collisions will not cause a reaction so the player will fall through the floor.. right after the collision ends you can reactivate the collisions by setting sensor to false again Link to comment Share on other sites More sharing options...
Recommended Posts