Game bodies which don't quite follow rules of physics?

First let me thank you guys for this library, browsing through examples made me very excited and I immediately want to test it out!

I would like to create a simple 2d platform game. Most of stuff should be governed by rules of physics but some deviations are required, and 2 problems immediately crossed my mind and cannot really figure it out.

1. player (or any other monster): I imagine these guys as boxes, which are always axis aligned (they don’t flip over even when standing on narrow ledge) and magically move by constant velocity in horizontal direction. Vertically, they should follow laws of physics. Horizontal movement speed should be constant, not discrete nudges.

2. every platformer has these little elevators which go up and down (or sideways) and never stop and can move other things on top of them! What would be most suitable representation? I can imagine appending elevator to a Fixed join and translating it around (assuming I read code in 2d testbed correctly). Now I only need to disallow rotation (add a second joint?).

So, that’s it. I would appreciate suggestions how to proceed! Thanks.

Hi! Regarding disallowing rotations (for the player and the platform), you may simply set the angular inertia to zero. To do that, you need to call the RigidBody::new constructor with the `AgularInertia` on the second tuple-argument set to zero.

The proper way to handle moving platforms would be to use what other physics engines call “kinematic bodies”. Unfortunately, they are not yet supported by nphysics and I don’t think there is a very clean workaround. The issue with translating the fixed joint around as you propose is that a player resting on a moving platform won’t move simultaneously (because the platform will virtually have no velocity). So you may have to handle that yourself using impulses when the player is in contact with the platform.

Regarding the player, the simplest method would be to control its movement applying impulses at each timestep. You might want to tune the friction and restitution coefficient to prevent him from getting stuck because the impulse is not strong enough, and to prevent him from bouncing against walls.