Moving across multiple physic platforms

Hi,

I have a character with a physic body moving across the screen, he runs fine on top of a rectangle with a physic body added, but if I have 2 physic body rectangles next to each other the object falls through the 2nd. If I have the y axis of the 2 objects separated by 15 pixels then the collision works but not when less or level with each other. Has anyone had this before or know the cause?

Thanks

You need to post some code showing the setup and your collision listener.

Hi,

I’ll post some later when I can, but as for the collision listener, that doesn’t really matter as I have no filters etc setup. The floors are static and the player is a regular dynamic body. The listeners don’t do anything to stop the objects colliding.

Cheers

I would suggest boiling your code down to it’s simplest components and post that. Let’s see where the issues lies without any distractions.

Hi I had just finished doing that and was about to update to say I know the issue. I have the gravity set to 0,0 and move everything with math rather than physics. I just use the physics for collisions. When off the ground and jump is off the math is along the lines of player.y = player.y +15 to make them fall.

The problem I’m getting is that when moving from one platform to the other, even though they are right up to each other or overlapping the collision ended event is triggering the offGround setting causing the player to jump through the ground. I’ll probably fix it by removing physics and just using math to detect if the player should be on the ground.

Thanks for the help.

If you are trying to move physics bodies with absolute positioning by setting their .x and .y values you’ll have a bad time. You are essentially fighting the physics engine and this will lead to unpredictable results. You need to make sure that the bodies are sensors, at least. The recommended way to move bodies absolutely is to attach a touch joint to them and move that. This way you’re moving them using the physics engine mechanisms and not just trying to force your will upon it.

You need to post some code showing the setup and your collision listener.

Hi,

I’ll post some later when I can, but as for the collision listener, that doesn’t really matter as I have no filters etc setup. The floors are static and the player is a regular dynamic body. The listeners don’t do anything to stop the objects colliding.

Cheers

I would suggest boiling your code down to it’s simplest components and post that. Let’s see where the issues lies without any distractions.

Hi I had just finished doing that and was about to update to say I know the issue. I have the gravity set to 0,0 and move everything with math rather than physics. I just use the physics for collisions. When off the ground and jump is off the math is along the lines of player.y = player.y +15 to make them fall.

The problem I’m getting is that when moving from one platform to the other, even though they are right up to each other or overlapping the collision ended event is triggering the offGround setting causing the player to jump through the ground. I’ll probably fix it by removing physics and just using math to detect if the player should be on the ground.

Thanks for the help.

If you are trying to move physics bodies with absolute positioning by setting their .x and .y values you’ll have a bad time. You are essentially fighting the physics engine and this will lead to unpredictable results. You need to make sure that the bodies are sensors, at least. The recommended way to move bodies absolutely is to attach a touch joint to them and move that. This way you’re moving them using the physics engine mechanisms and not just trying to force your will upon it.