I’m trying to connect two rigid bodies with a spring joint in between them and have some question. Mind you, even though I’m trying specifically with a spring at the moment, some of these questions are really about joints in Unity in general:
-
Is it possible to model a spring
with two ends and one body on each
end and have the 2 ends behave the same with respect to each other?For instance, in Apple’s SpriteKit,
which under the hood uses box2d, a
spring joint connects one body with
another (it hasphysicsBodyA
and
physicsBodyB
properties and
anchorA
andanchorB
properties).
That is, both bodies and anchor
points are at the same hierarchical
level. In Unity however, I’m
confused about the hierarchy and the
ConnectedBody
vsAnchor
implication. It seems as if at some
point, a joint is a one-way
relationship: the body you add the
spring to becomes the “free” end of
the spring and theConnectedBody
property, even if referencing
another body, does not allow this
other body to move in the same way
the parent of the joint component
moves.The best example I can think of is
this (assume A and B are rigid
bodies with say, box colliders).- A has
SpringJoint
component -
SpringJoint.ConnectedBody
= B
Rotating A around B will cause B to
rotate about its center as if
“watching” B, which I’d expect.
However, attempting to rotate B
around A does not make A to rotate
in place but instead to start
strafing towards B until it ill end
(for an attempt at rotating 90 degs
for instance) almost horizontally
aligned with B. Maybe this drawing
helps:
I wonder if it might have something to do with Unity’s definition of a spring having a “fixed” end? But if so, would I need to coordinate two spring joints (from A to B and B to A) to get the effect of a single spring with two “free” ends?
- A has
-
Is it possible to have bodies connected thru a joint to still
collide and repel each other? If
not, is there a sensible way to fake
this?I’ve done some initial testing and
it doesn’t seem like it is. For
example, if A has a joint and that
joint’sConnectedBody
is B, from
that point onwards A and B can
intersect each other, which kind of
sucks… cause I’m trying to create
a sort of physics-affected graph:
nodes connected by edges (which
would behave like springs for
instance) and connected nodes should
still not intersect each other on
colliding. -
What determines the distance between the two bodies joined by a
joint? First I thought that their
distance at the time of creating the
joint was what would get set as the
joint length if you will (though
this might only make sense if I
think about the joint itself as an
elastic rod or spring?). Then I
thought the min/max distances of the
spring joint or the linear limits in
the configurable joint would set
this. But I get strange results. Say
I want A to be joined to B by a
spring and the distance between A
and B (the spring length if you
will) be 10 units. How do I
establish the 10 unit distance? -
Is it possible to change at runtime the length of the joint /
distance between two joined
bodies? Following on the previous
example, say at runtime I want to
change the distance between A and B
from 10 to 5. How would I go about
it?