w0rm / elm-physics

3D physics engine in Elm
https://package.elm-lang.org/packages/w0rm/elm-physics/latest
BSD 3-Clause "New" or "Revised" License
146 stars 12 forks source link

type of constraint that links two bodies, including rotation? #92

Closed CSchank closed 4 years ago

CSchank commented 4 years ago

Hi, we're designing a space game where a ship has many components (e.g. fuel tanks, boosters), each with a different mass. We could combine our ship into a Compound but then we can't allow different parts have different masses. We've been able to kind of simulate this by having three hinge constraints, one for each axis, but this seems to break down if the bodies are overlapping at all at the start, or if they go beyond a certain acceleration value. Sometimes wonky things happen even without going beyond a certain acceleration. Would it be possible to add a new type of constraint like the point constraint that also constrains the mutual rotation?

w0rm commented 4 years ago

@CSchank hi! What you probably want is a lock constraint that would remove all degrees of freedom between bodies. I wonder what the API should be for this. Should it just take two bodies and lock them relatively to each other in the world coordinate system, e.g.

lock : Body data -> Body data -> Constraint

Or should it take two frames defined within bodies' coordinate systems and lock them together

lock : Frame3d Meters BodyCoordinates -> Frame3d Meters BodyCoordinates -> Constraint

but this seems to break down if the bodies are overlapping at all at the start

I would like to know more about this use case. Do you want to connect bodies that are slightly misaligned initially? If this is the case, then probably the second option makes more sense.

w0rm commented 4 years ago

Addressed via #93