diff --git a/include/gz/sim/components/Gravity.hh b/include/gz/sim/components/Gravity.hh index fe3cf88a9f..713e797acf 100644 --- a/include/gz/sim/components/Gravity.hh +++ b/include/gz/sim/components/Gravity.hh @@ -36,6 +36,11 @@ namespace components /// \brief Store the gravity acceleration. using Gravity = Component; IGN_GAZEBO_REGISTER_COMPONENT("ign_gazebo_components.Gravity", Gravity) + + /// \brief Store the gravity acceleration. + using GravityEnabled = Component; + IGN_GAZEBO_REGISTER_COMPONENT( + "ign_gazebo_components.GravityEnabled", GravityEnabled) } } } diff --git a/src/SdfEntityCreator.cc b/src/SdfEntityCreator.cc index a84343fd42..71c295db9b 100644 --- a/src/SdfEntityCreator.cc +++ b/src/SdfEntityCreator.cc @@ -590,10 +590,9 @@ Entity SdfEntityCreator::CreateEntities(const sdf::Link *_link) if (!_link->EnableGravity()) { - // If disable gravity, create a gravity component to the entity - // This gravity will have value 0,0,0 + // If disable gravity, create a GravityEnabled component to the entity this->dataPtr->ecm->CreateComponent( - linkEntity, components::Gravity()); + linkEntity, components::GravityEnabled(false)); } // Visuals diff --git a/src/systems/physics/Physics.cc b/src/systems/physics/Physics.cc index c61279205f..687178a369 100644 --- a/src/systems/physics/Physics.cc +++ b/src/systems/physics/Physics.cc @@ -1161,21 +1161,12 @@ void PhysicsPrivate::CreateLinkEntities(const EntityComponentManager &_ecm) } // get link gravity - const components::Gravity *gravity = - _ecm.Component(_entity); - if (nullptr != gravity) - { - // Entity has a gravity component that is all zeros when - // is set to false - // See SdfEntityCreator::CreateEntities() - if (gravity->Data() == math::Vector3d::Zero) - { - link.SetEnableGravity(false); - } - else - { - link.SetEnableGravity(true); - } + const components::GravityEnabled *gravityEnabled = + _ecm.Component(_entity); + if (nullptr != gravityEnabled) + { + // gravityEnabled set in SdfEntityCreator::CreateEntities() + link.SetEnableGravity(gravityEnabled->Data()); } auto linkPtrPhys = modelPtrPhys->ConstructLink(link);