2d physics

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
dynamoman
Posts: 12
Joined: Mon Sep 27, 2010 12:35 am

2d physics

Post by dynamoman »

Hello, Ive just started using BEPU and so far looks good and has a great support on the forums, but Im having some issues and would like some tips on how to get my physics running as I want them.

Im trying to program something similar to new super mario bros, its pretty much 3d physics restricted to 2 axis(I have no issues with this), but in our game there are no slopes, all the environment meshes are boxes, and we would like to use boxes for the players too(I have this working too so far). I tried using both character controllers changing the bodies to boxes, but Im having some issues:

1) when a character jumps or falls from a very high distance, there is a very small lag, like if the box is colliding with the floor and moving up, the lag is very small, like half a second, but if possible we would like to not have any lag at all.

2)Friction, when I jump next to a wall and keep pressing in that direction, the character gets stuck in the wall until I release the key, and in that moment the body fall as expected, I tried setting friction to 0 and to use frictionblendmethod.min, but it still gets stuck.

3)When one player falls from a very high distance on top of the other player(is a 2 player game), the second character(the one on the floor), gets pushed down, and then it restores his position, we would like to be able to just jump on top of the other with no lag and no pushing down the other character.


The physics Im trying to replicate are very similar to megaman powered up: http://www.youtube.com/watch?v=Oz3qerUSCIs , or new super mario bros wii: http://www.youtube.com/watch?v=GpcJNEWKzCY

Any help would be greatly appreciated, thank you.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: 2d physics

Post by Norbo »

1) when a character jumps or falls from a very high distance, there is a very small lag, like if the box is colliding with the floor and moving up, the lag is very small, like half a second, but if possible we would like to not have any lag at all.
Is it a pause or a gradual motion upwards? Does it happen with both character controllers? Is continuous collision detection enabled (it's off by default)?

Gradual motion is expected if it gets a large amount of velocity before impacting. It will be partially penetrating the ground, and depending on the type of character, it won't be able to resolve that penetration instantly. This problem would probably be more noticeable with the CharacterController (non-Simple).

Enabling continuous collision detection (Space.SimulationSettings.CollisionDetection.CollisionDetectionType = CollisionDetectionType.LinearContinuous or FullyContinuous) could help prevent excessive penetration.
2)Friction, when I jump next to a wall and keep pressing in that direction, the character gets stuck in the wall until I release the key, and in that moment the body fall as expected, I tried setting friction to 0 and to use frictionblendmethod.min, but it still gets stuck.
It could be latching onto intersections in the geometry. If it's a StaticTriangleGroup, try increasing the range in which the triangle's normal is used.

Code: Select all

group.UseFaceNormalWithinAngle = (float)Math.PI / 2;
Capsules or other smooth shapes generally have an easier time with this too. A box's hard edges tend to 'catch.' I plan to improve the intramesh collisions as well.
3)When one player falls from a very high distance on top of the other player(is a 2 player game), the second character(the one on the floor), gets pushed down, and then it restores his position, we would like to be able to just jump on top of the other with no lag and no pushing down the other character.
Turning on CCD might help this some. 'Fixing' it entirely may require redesigning the supporting function to integrate with the collision solver. I'm not exactly sure of the behavior you're describing, though.

I should mention that using 3d physics for a fundamentally 2d game will introduce some hassles. Unless there are some 3d physics components, you might have an easier time with something like Farseer.
dynamoman
Posts: 12
Joined: Mon Sep 27, 2010 12:35 am

Re: 2d physics

Post by dynamoman »

thanks for the reply, I did change it to continuous detection and it improved a lot, and Ive playing with friction and got some better results, our game has 3d elements, but most of the time it behaves like 2d, thats why we want to use a 3d physics engine, we considered using spheres, but we also want to be able to stand on the edge of a surface and not to fall, and also to have one player on top of the other(like mario wii), and spheres would slide or not look right, thats why we decided to use boxes, although cylinders may be a good idea too.

But what do you think would be the best approach for this kind of game, we do need 3d physics, but most of the time is just 2d, and when it is 2d, we want to have physics similar to old 2d platform games(mario, battletoads, contra, megaman, etc). Do you think using boxes and the character controller is a good idea, or what would you suggest for us to do?

Thanks in advance
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: 2d physics

Post by Norbo »

Boxes or cylinders for the character controller can work, but it does require dealing with the wall-sticking you encountered earlier.

The box/cylinder approach requires that the non-simple character controller is used with its area-sweep based support finding. When changing the shape to something besides a cylinder, you'd need to make sure it is changed too.

Of course, you can also make adjustments to the character controller's systems too. You might find that a different type of support finding or stepping management works better for your game.
Post Reply