Transition.to moving player through static physics objects

I have borders in my game which are static physics objects.  The player should NOT ever be allowed to move through them.  

My problem is that I am using transition.to for all my player movement and if I click on the other side of a physics border, the player walks right through the object, despite that it’s static. 

I read that the way to handle this is by cancelling the transition.  

This only works if I just click one time.  But on the second click, the player proceeds to move across the border since the collision doesn’t happen at that point.

Can anyone help me out with a way to stop the transition.to from moving through the static physics object?

In general, you don’t want to use transitions to move around dynamic physics objects. I’m assuming your player is a dynamic object. The problem is that even though the physics engine tries to handle the player’s movement, the transition is constantly fighting it and taking control and this will result in all sorts of weird behaviour. Then again, if your player is also a static physics object, then you run into the issue where only dynamic objects can collide with static objects to begin with.

If you must move physics objects with transitions, then make sure that the object you are moving doesn’t have a dynamic type body.

I actually don’t need physics interaction with the player at all, except to prevent them from moving through walls.  I tried adding isSensor=true and just cancelling the transition when they hit the wall, but I still have the same problem, the 2nd time they try to move though the wall, since the onCollision doesn’t happen again, they just walk right through. 

Removing transitions and using forces would require a substantial amount of code to be rewritten so I’m trying to see if there’s some trick I can use to get by for now that will stop the movement through the boundaries. 

Well, the issue there is that you need to track when a collision begins and when it ends.

The collision event won’t “begin” again before it has “ended”. If you are stopping the transition when the player collides with the wall then you can only do so once because the collision won’t stop until you move the player away from the wall, which won’t happen until you give it a new movement order using your transition setup and move the player away from the wall, but at this point the player can just as well choose to move outside, i.e. you have a problem that requires extensive rewrites in any case.

I’m toying with the idea of just making the player instantly explode if they hit a wall.   :smiley:

Seems like the easiest solution for me.  =P

If anyone stumbles upon this issue, I was able to make a workaround:

  • Created a timer which stores the location of the player every second

  • When the player runs into a wall or border

       - cancel the active transition on the player

       - use the stored location to figure out the direction the player was in before hitting the wall

       - transition the player in that direction by however much you want the player to “bounce” off the wall (i used a very short time for this transition)

       - I also disabled the touch listener during this short transition time and re-enabled it after

It’s not the most elegant solution but it seems to get the job done and my character is no longer walking through walls.  :-) 

Thanks to XeduR @Spyric   for helping me think through this one.