Create something like rhusics-ecs

feature

#1

Hi I’m been playing around with rhusics and I really loved the integration with Specs using rhusics-ecs, would be possible someday to have something like that for nphysics?

Regards,


#2

Hi!

We can consider adding official support for this in the future. I’ve not yet took the time to assess the amount of work that would represent. I know at least two examples of nphysics integration with Specs: stacked-worlds and airjump-multi. It may be interesting to draw some inspiration from this.


#3

Hi Sébastien, thanks for taking your time to reply.

Yeah I’ve been “stalking” those repositories for a while, trying to draw some very basic examples to teach myself and help others to get on the track with rust gamedev.

I’ve made this sample using nphysics+specs+ggez, following a series of basic repos I’m doing to try learn rust with gamedev.

But the collision between bodies is acting like the cuboids have rounded corners, this happens more often when colliding dynamic bodies (probably I’m missing something).

All this to justify how awesome would be to have some ECS integration to minimize the boilerplate and the friction to use the nphysics with the ECS.

Thanks again for your time and work!
Best regards.


#4

Thank you for the link!

The issue here is related to rotations. You either need to take rotations into account when drawing your objects (otherwise your render does not reflect the actual state of the physics scene), or lock the rotation of the bodies that move by setting their angular inertia to 0:

let mut inertia = shape.inertia();
inertia.angular = 0.0;

Two additional remarks:

  1. You should not use pixels as length units for physics. nphysics generally assumes length units to be 1.0 unit = 1 meter. Therefore, when you are creating a Cuboid with a side length equal to 50, you are actually saying it is 50meters wide! You should use smaller objects, and draw them with some scaling factor. But saying that 1pixel in the render world = 1meter in the physics world will lead to problems at some point (because of rounding errors of floatting point numbers).
  2. Keep in mind that, in your case, the position of the rigid bodies correspond to the position of the center of the square, not of the top-left corner of the square. This should be kept in mind for rendering, especially if you add rotations to your game.

Yes, a tutorial for ECS integration is definitely something worth considering. I will keep this in mind once I’ve finished my current developments on deformable bodies.


#5

Hi,

I’ve made some changes following your suggestions and everything is working fine now, I even added multiple shapes types and sizes.

Thanks again.