- Home /
Physics based vehicles made from rigidbodies
I have an empty game object that I consider the root object for a bunch of prefab cubes of type, Regular, Weapon, and Movement.
Block Types: Regular: provides structure and a place for other nodes to attach. Weapon: attaches to Regular nodes and can shoot. Movement: provides thrust in a desired direction.
Block Prefab Contents: Blocks consist of: Script for controlling that type of block, a 1x1x1 cube primitive, rigid body with gravity enabled and a mass of 1, cube collider.
So with these block types you create a vehicle. Adding them all to 'root' empty game object node.
On your movement function you apply force to your engines and that is when it all breaks down.
I want to move all the cubes as one unit. I figured one way is to add fixed joints to each of the nodes and add it's adjacent node. This worked alright except there was some noticeable jiggle if I messed up thrust and the ship toppled over. It didn't look 'glued' together. How do I make these blocks stick to each other while manipulating the 'thrust' from my engines and make the entire ship behave as a single unit.
Edit: So one possible solution is to remove the rigid bodies from all the individual blocks, add one to the root gameobject that everything is a child of and add force to that. It will work well enough but what are the options for an entire physics based vehicle that is created from modular parts?
They do have the same parent, It's the empty game objects I called 'root'. I'm taking about using physics on the entire thing with discrete physics calculations per block.
I might just have to fake it and use math to calculate what the characteristics should be for a vehicle
I can provide a screenshot when I get back to my machine. But I thought I summed up what I did pretty well in my question. I have blocks with rigid bodies I added fixed joints to each of the cubes to link them together as if I was welding. But it doesn't look like the joins are completely solid, if the object hits something too hard the 'ship' will jiggle as if the joints are made of jello.
The problem is I have a group of individual blocks each with rigidbodies and 4 movement blocks that apply force down to lift the object. Is there a better way to do that?
Yeah but I'm at work, I can't try anything out or post pictures, because I don't have my project.
Answer by nixtwiz · Oct 04, 2012 at 05:48 PM
Why are you using multiple rigidbodies? If you want them to all appear "glued together" then the root object is all that needs a rigidbody. Just make the Empty Gameobject that is the root be the only object with a rigidbody and everything that is a child of it will move with it. It will take into account all of the children collision meshes.
As for having multiple thrust locations, just use rigidbody.AddForceAtPosition and use the different locations you were trying to set as separate "thrust" rigidbodies.
AddForceAtPosition is totally going to solve my problems. Thanks for that, I was exhausted yesterday and should have just rested rather than tried to program anything.
Your answer
![](https://koobas.hobune.stream/wayback/20220613081838im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
fast forward physic vehicles 0 Answers
How do you not allow a car to flip with Edy's phyics? 0 Answers
Bouncing off Walls in C# 1 Answer
Problem with Rigidbody2D: Objects are sticking together when instantiated? 0 Answers
Vehicle programming source 5 Answers