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.