- Home /
Compound Collider Moving Parts?
Hey everyone. I hope someone can help me out with this. I made a 4 legged robot, with the leg sections parented so they can bend and each has a collider. The root object has a rigid body component. I'm writing a genetic algorithm to teach the robot to walk on its own. When the robot bends its legs, the physics should react somewhat realistically, then the robot will be able to learn to walk.
Currently, the robot acts as a compound collider (that's what I want), until I rotate the legs through scripting. When the leg lifts off the ground, it acts as expected. The robot will tip to the side. But when the leg bends toward the ground, the leg passes through the ground instead of pushing against it.
The objects are all slow moving, and all have colliders. I have tried different types of colliders, which didn't work. Do you have to do something to "update" the compound collider if you move one of the objects? Or can they not be moved? Some help would be greatly appreciated.
Answer by IgorAherne · Aug 13, 2013 at 05:17 PM
if your ground is plane and has a collider without height, remove the ground collider and add the one which has height.
It's a cube, so that's not the problem. But that happened to me a long time ago. It took me forever to figure it out haha
Answer by janzdott · Aug 13, 2013 at 05:49 PM
I found a solution, though it's not perfect. After moving one of the parts, disabling then immediately enabling the root gameobject will cause it to react to the moved part. The reaction looks snappy and incorrect, so I hope there's another way.
EDIT: Yep, I'm not pleased with this solution. I tested some physics on robotic joints using ConfigurableJoint, and it's much, much better. The only problem is setting up all the joints (there's lots of them, and ConfigurableJoints aren't the fastest to set up). So I'm actually writing a Servo class, which uses ConfigurableJoints under the hood. It's coming along nicely, and I'll put it up on the Asset Store for free when it's done. Maybe someone will find it useful.
Any updates on your solution, I currently have I$$anonymous$$ controlled leg armature with capsule collider children in each bone, it all works as expected, but the act of setting the bones transform data (pos and rot) causes the rigidbody to drift unexpectedly.
Any solution that allows compound rigidbodies with moving childed colliders, would be greatly appreciated
He wasn't online for more than two years, so don't expect any response.
Thank you, I will be more observant in the future. Since I know you have been super helpful in the many questions I have read through over the years, perhaps you could help me.
A rigidbody with childed colliders (compound rigidbody?), has ik's moving said colliders. This causes the rigidbody to drift unexpectedly. I assume this is because of Rigidbody "combining" the colliders when entering runtime and most likely expecting them not to change shape/move after that. Any ideas as to a way forward, without recreating a rigidbody script that can handle dynamic colliders?
Turning colliders off or ik system off will stop the drifting, so it seems isolated to dynamic colliders
Answer by Psyco92 · Oct 20, 2016 at 11:42 AM
The solution i found was too :
Create a sphere collider as a child to your rigidbody.
Scale it so it well encompasses you entire collider structure.
Put it on a new layer for that interacts with nothing.
My guess as to why this works is that due to all the moving colliders being inside the large sphere collider, there is technically no shape change to the rigidbodies outer shell. Would be nice to know from someone with more intimate unity knowledge
Answer by Pangamini · Oct 20, 2016 at 12:16 PM
The problem here is misunderstanding the physics engine in general. To make a physical robot walk, you need to build it using rigid bodies, not just colliders. Meaning that each moving part (part of the leg) needs to be a separate rigidbody. Then you need to connect these bodies using joints, and then you can move the robot by applying forces to these joints.
In case you want to control the motion by an animation or code that directly affects the positions, you need some way how to calculate forces on the rigidbodies from this data. Eg. you make some "spring" code that tries to push the rigidbody (using forces) towards desired position (calculated by animation). Moving the rigidbody by setting its position is not percieved as "motion" in the phys. engine, and such object will still have zero velocity.
I disagree, but that is a way of doing it. I have 8 legged characters (spiders) with a single rigidbody on the parent that is non-kinematic. Set up is :
Rigidbody parent with animator set to animate physics
Capsule colliders on each bone transform inside an armature
Each leg segment is controlled with I$$anonymous$$ scirpts that modify the bone transforms
Gameobject childed to root with a spherical collider that well encompasses the entire character and has its own layer that interacts with nothing
This setup works great with the physics system and has accurate collisions.
Your answer
![](https://koobas.hobune.stream/wayback/20220613112127im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Making a sphere move and rotate like a real ball on ground 2 Answers
Rotate multiple objects around or rather move them on the surface of another object 1 Answer
Only take into account colliders' bounds on single gameobject in hierarchy 1 Answer
Need help with physics 1 Answer
Ignore sub-colliders for center of mass in Rigidbody2d? 1 Answer