I'm doing a project in unity where I turn off the general gravity and implement it myself. What I'm trying to acheive is to have GameObjects be affected by several gravity sources on every tick. I got to a dilemma where I'm not sure where the responsibility of the physics calculation should rest. Should I:

a) Have GameObjects (more specifically, their component which I call GravitySubjects) pull themselves to gravity sources?

b) Should gravity sources pull gravity subjects toward them?

c) Should I have some kind of "manager" class that calculates all the physical steps for gravity subjects and gravity sources?

Here's my current UML:


The newfangled Entity-Component-System design says to use option C. Have the system grab all gravity-subject components and gravity-source components and use the position component of the attached entity do the calculation and commit the updated position to the position component.

ECS is designed so that Entity's only responsibility is to collect components. Components are responsible to hold the state (nothing else, just hold state). And the System is what is responsible for calculating what it needs by iterating over the components and possibly updating them.

  • Thanks. That makes a lot of sense. I can see how it fits with Unity game engine – PanthersFan92 May 2 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.