thombruce / verse

🚀 A universe in progress
Other
8 stars 0 forks source link

Orphaned Orbits #38

Closed thombruce closed 11 months ago

thombruce commented 11 months ago

closes #37

By submitting this pull request, you agree to follow our Code of Conduct: https://github.com/thombruce/.github/blob/main/CODE_OF_CONDUCT.md


Internal use. Do not delete.

thombruce commented 11 months ago

Problems:

First: In order to support moons and other satellites, the Orbit system needs to be able to query first for orbiting bodies then for bodies these are attached to (via the parent attribute on the orbit component). However I am unable to come up with a satisfactory solution to querying these similar entities twice... it's just not allowed. I'm probably trying to apply an OOP mindset to an ECS problem.

I had a second issue, but I've forgotten it. It might be covered above; will add if I recall it.

thombruce commented 11 months ago

Okay, so I've had a little brainwave and I think the ECS way to do this is...

  1. Create something like an Orbitable component with a Vec2 or Vec3
  2. Create or add to a system a function that updates these orbitables
  3. Query the Orbitable instead of the Transform, negating the conflict from borrowing the same type?

The orbitable_update_system can be very simple:

pub fn orbitable_update_system(mut orbitables: Query<(&mut Orbitable, &Transform)>) {
    for (mut orbitable, transform) in orbitables.iter_mut() {
        orbitable.position = transform.translation;
    }
}

And we would query this orbitable for the position of the "parent" body instead of the Transform which conflicts with querying for the same value as a mutable...

It's confusing. It's counter-intuitive... sort of. But it seems to work.