Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend RigidBodyComponent to include useGravity and gravity #5163

Open
wants to merge 37 commits into
base: main
Choose a base branch
from

Conversation

MushAsterion
Copy link
Collaborator

@MushAsterion MushAsterion commented Mar 17, 2023

  • Requires to update Ammo.js to latest version. (which is not a breaking change)
    • Requires exposure of setFlags (and optionally getFlags for counterpart) from Ammo.btRigidBody to work

Allows a better management of gravity for rigid bodies.

Changes to pc public API:

  • BODYFLAG_GRAVITY_WORLD_ENABLE: constant to enable world gravity on body
  • BODYFLAG_GRAVITY_WORLD_DISABLE: constant to disable world gravity on body
  • BODYFLAG_GRAVITY_GYROSCOPIC_EXPLICIT: constant to enable explicit gyroscopic forces
  • BODYFLAG_GRAVITY_GYROSCOPIC_IMPLICIT_WORLD: constant to enable implicit world gyroscopic forces
  • BODYFLAG_GRAVITY_GYROSCOPIC_EXPLICIT_BODY: constant to enable implicit body gyroscopic forces
  • BODYFLAG_GRAVITY_GYROSCOPIC_ENABLE: constant to enable all gyroscopic forces

Changes to pc.RigidBodyComponent public API:

  • useGravity: boolean, defining whether or not the body should use gravity.
  • gravity: Vec3 to represent gravity applying only to this entity. Defaults to null (use world gravity).

I confirm I have read the contributing guidelines and signed the Contributor License Agreement.

@MushAsterion MushAsterion changed the title Use gravity Extend RigidBodyComponent to include useGravity and gravity-related functions Mar 17, 2023
@willeastcott
Copy link
Contributor

Could this API be simplified to:

RigidBodyComponent#gravity (Vec3)

If set to null, simply use world gravity.

@MushAsterion
Copy link
Collaborator Author

Could this API be simplified to:

RigidBodyComponent#gravity (Vec3)

If set to null, simply use world gravity.

Unfortunately Vec3 don't have events on modification which means it will need to loop to every single rigid bodies and make sure their gravity has not changed before simulating the next step, which also add a for loop in RigidBodySystem#update. Honestly I'm not sure it would be good for performance. RigidBodySystem is having it at a Vec3 but it's only one check so not a very high impact compared to RigidBodyComponent that could be present in large number. And I'm not sure adding a set event on Vec3 would be good for performance as well...

@willeastcott
Copy link
Contributor

I don't get how this is different to CameraComponent#clearColor for example. You can't do camera.clearColor.r = 1;. Instead, you can only do camera.clearColor = new pc.Color(1, 0, 0);. It's just a limitation of the entity-component system that you can't set individual properties on vectors/colors/quaternions/etc.

@MushAsterion
Copy link
Collaborator Author

I don't get how this is different to CameraComponent#clearColor for example. You can't do camera.clearColor.r = 1;. Instead, you can only do camera.clearColor = new pc.Color(1, 0, 0);. It's just a limitation of the entity-component system that you can't set individual properties on vectors/colors/quaternions/etc.

Oh alright, I have to admit I don't use the whole API so I have not seen all the variation but yeah it makes the code much more simple, I was just afraid about the clarity to users that they should not edit the base value. It's updated then!

@MushAsterion MushAsterion changed the title Extend RigidBodyComponent to include useGravity and gravity-related functions Extend RigidBodyComponent to include useGravity and gravity Mar 17, 2023
@GSterbrant GSterbrant added the open source contribution Issues related to contributions from people outside the PlayCanvas team label May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: physics Physics related issue feature request open source contribution Issues related to contributions from people outside the PlayCanvas team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants