Question

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:

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
scroll top