I have the following setup:
-
kinematic rigid body with a child rigid body attached thru a spring joint. That is, in the child, the connected rigid body is its parent, the kinematic one.
-
I translate this kinematic rigidbody by setting its transform in response to user input (Y Input axis = speed up / down).
Basically, this:
Note that the parent doesn’t have a collider nor a mesh. This is because it’s really only the child that will be visible in game and that I care about colliding with other stuff.
What I’m trying to achieve is that, if I’m ‘accelerating’ the kinematic body forward and all of a suden I break, have the child keep moving forward for a bit, before going back into place as a result of the spring. That is, I need momentum if you will. But what happens is that, while if I add a force to the child it will oscillate as expected cause of the spring, the parent’s translation obviously does nothing in terms of imparting an acceleration in the child as it moves forward. I’m wondering if there is a way to do this with my setup (i.e.: dynamic body attached to a kinematic parent via a spring).
I tried rigidbody.MovePosition
but it doesn’t seem to affect the kinematic body, though I might just be using it wrong.
Just in case, the reason why I make the parent kinematic and translate it via it’s transform instead of having it be dynamic and add forces to it is cause I’m having it follow a bezier path and otherwise I’d need to calculate several forces to keep it moving on the path. Instead, I’m calculating acceleration, speed (not velocity) and position myself and keeping the body always on track by evaluating the bezier function and assigning the right values to transform.position
and transform.forward
.