I am developing a game where a person can create their own drone. The editor is setup, the joints are fixed, but when i fire up the thrusters, which are positioned precisely opposite each other and give EXACTLY the same amount of thrust, the drone leans heavily sideways, instead of going directly up. I am using AddForce with transform.up .
Physics are not predeterministic. This means that there is not an “exact” way physics will react, and doing the same simulation twice can give different results.
So even though mathematically your sideways forces should be canceling each other out, on the computer there will be slight differences. Over time these slight differences can add up pretty quickly causing your drone to start rotating.
This means either don’t use physics where you need exact interaction, or use JamesLeeNZ’s excellent idea and counter-balance the discrepancies.
It should work… are you sure your thrusters are absolutely in right places? They need to be exactly opposite places from center of mass. You say you use rigidbodies in your thrusters, so check you got exactly same settings with all of them.
Just found out it has something to do with the configurable joints. Does anybody know the EXACT definition of the following variables (the documentation is quite bad on configurable joints):
Do you really need to use rigidbodies and joints with your thrusters? My quadcopter simulator was similar to your drone, but my setup was different:
R1 R2
X
R3 R4
Where r1-4 are rotors and they are child of X (the body). Only X has a rigidbody, and r1-4 are places what i use to add force (rigidbody.AddForceAtPosition). Works well, and copter hovers like without any problems. Perhaps you should try similar setup?
edit: X should be in center …but forumsoft doesnt seems to like spaces
My aim is to create a game where the player can design their own drone. I’m thinking of maybe using my own system to simulate the flying physics, as i don’t need it too precise.
You dont need joints to react with the environment
In an early development of my game I wrote a system that allowed parts of my ships to get smashed off when they collided with something. There were not joints involved, I just used the contact data in the collision event
Thats actually a good idea
What would be the best procedure: using parenting or coding to make them stick together?
I would still need plausible looking physics for my motors (eg. that if a motor gets smashed off, the drone starts spinning), so any theories on how to apply that? Should i use built in functions or write my own?
I would go with parenting, so that if a parent gets smashed off, it takes the children with it, which is a more realistic result (otherwise you might end up with children floating in the air not attached to anything).
I would go with something custom… every part creates directional forces… ie a helicopter rotor would create up + right forces (clockwise)
A tail rotor creates -right forces.
so when you calculate your up/right/down/etc forces, you just add up the totals and then add force based on the results.
so it might look like this
Rotor +10 up, +5 right
Tail -5 right
adding them together you would get +10 up, 0 right, so you only add lift, however, you smash off the tail rotor you end up with +10 up, +5 right, making it climb but also spin uncontrollably.
What would be the best way to apply the calculated forces? Through the transform or kinematic rigidbody? Directly changing values or through helper functions?
Where should i apply the forces: to the centre of gravity or to the main parent?
AddForce, AddTorque, etc. If you want realistic physics that is. If you go kinematic its easier, but you have to control everything.
I would do it on the parent for simplicity. If you start offsetting the force centers, you will have to use more complex values to counter balance any force you apply