I’m trying to make a space shooter style game. I want the player’s ship to be ‘breakable,’ meaning that if you run into something, you watch the pieces break apart, exploding individually.
For this purpose, I created a .fbx with every breakable part of the ship as an individual object.
I then connect all the objects to the main deck using fixed joints.
Then I connected the main deck to the main engines using another fixed joint.
The engines are not jointed to anything, but they do have rigibodies.
I then added constant force components to each engine, with the intention of moving the whole ship, via the fixed joints that connect them to the engine.
When i played a quick test, rather than the whole ship moving, the engines broke free immediately and spun off into infinity moving the ship only by occasionally crashing into it and bumping it’s rigidbodies. A few moments later and every other part of the ship started vibrating violently, just before they burst apart, spinning at speeds so great that they exceeded the game’s framerate. I can kind of explain all of this in my head if the fixed joint broke, and on the way out, the engines nudged the ship causing some sort of vibration, but what happened next really puzzles me: after everything had spun off the screen, the engines returned. Either physics isn’t what I thought it was, or the fixed joints were still working in strange way i didn’t mean them to, like a spring joint. A few moments later and everything else returned too. They then proceeded to precess in and out of the screen in an entirely inexplicable fashion. What happened? What am I doing wrong? How should I best go about making a breakable spaceship using the physics engine?
nvm, I figured it out. The inertial drag of the rest of the ship objects was causing the engines to turn, which made them go crazy, and they broke off because of an error in the mesh which caused them to collide with their own housing. Everything’s good now, except one thing: the ship has a tendency to pitch up. I can fix this by adjusting the height of the engines, but this has no correlation to the center point of the rest of the model. does unity simulate air drag?
Im facing somewhat of a new problem now: No matter how high I put the break force on each fixed joint, they still move to a small degree. As a result the rigidbodies of the ship bounce off each other and the whole thing starts to vibrate. It looks almost as if each piece is dancing on the others. It only gets worse when the ship collides with something. Rather than breaking into a million piece on contact or remaining unchanged and surviving the crash, the fixed joints seem to choose a sort of middle ground: bouncing about like spring joints, shaking everything, then eventually returning to their rest position, occasionally with pieces stuck backward or upside down.
The collision meshes will be trying to sit overlapped, always causes horrid things with physics when that happens. It might be easier to have several prefabs of the ship in different stages of “broken-ness” with the parts as seperate objects which spawn when you hit something and just instantiate the next more broken ship in place of the previous.
You always see examples of randomly spazzing models in games where a ragdoll gets stuck in a wall and the engine spends ages trying to move the colliders apart.
You are going about this in a very bad way for performance and reliablity.(What I like to call the “Gmod” Contrapsion methed)
Instead of having each part its own piece you need to have one empty gameobject as the “Root” of the ship.
Parent all your pieces together to this root and then toggle on iskimatic on thier ridgidbodys so it turns off them.
Then script the pieces to break off when you want them to by turning off iskimatic on the ridgidbodys.(Can unparent them too but its not needed since the ridgidbody overrights the control the “Root” has in moveing them.)
Move the ship by moveing the “Root” not by useing physics to have the engens push the rear that pushes the piece in frount and so on.
Otherwise you will allways have it do a wiggleing movement as the stuff in frount isnt geting moved intill everything behind it is moved and bumping into the other stuff thus geting told by physics to move backwards and it just snowballs from there.
If you try to have each ridgidbody push each other you will get very odd movements as each peice affects another.
Best to have it all act as a single object untill you need somthing to break off.
Hope this helps… I do kindof run on at times.
==Some What Advanced Tip==
*Another thing is use bones and a skin (just like if you were makeing a charactor) to make the hole thing one draw call instead of (1 * (parts) calls), then use the bones as trasforms to move objects.