- Home /
How to move child with collider when parent has the rigidbody
I have a truck (parent) with a rigidbody attached. This truck has four stabilizer legs (children), each one has its own mesh collider. The purpose of the legs is to make contact to the terrain and stabilize the truck.
Currently, I'm moving the legs down using Vector3.Lerp to change the positions. But I might as well be using translate. The point is that I'm not using physics to move the legs, but I want to.
How should I do that?
My understanding is that in order to move the legs using physics, like addForce, setting the velocity or using movePosition, I need the leg to have a rigidbody attached. The problem is that it messes up everything else.
So any advice would be welcome.
How does it mess up everything else?
If they are hitting other colliders on the truck, you can correct that behavior by making all truck colliders ignore each other.
https://docs.unity3d.com/ScriptReference/Physics.IgnoreCollision.html
The colliders aren't hitting each other on the truck, but when I attach rigid bodies to the children, the truck's wheel colliders start to fall through the terrain.
Do you have a collider on the ground? If you do, then try to both spawn the truck considerably above the ground, like 30 cm, and try to change the collision detection to something else than discrete. If even that doesn't work, you'll need to increase the fixed time step. If that doesn't work, I really don't know what could be the problem.
Each rigidbody behaves physically independent. This is a problem with children because they still obey the rules of parent translation, rotation and scaling. If you want them to still stay relative, you need to use joints holding them together.
Your answer
Follow this Question
Related Questions
Rigidbody climbing stairs 2 Answers
Differences between object movement functions 1 Answer
Keep Horizontal Momentum after Jump 2 Answers
Why are these object passing through each other? 1 Answer
Non slippery movement 1 Answer