I currently have this helicopter assembly that im using for a controller. To prevent the helicopter from tilting to the side because of imbalances, i made the whole model massless and have it all welded to the red cube you see in the pic below, which contains the total mass of the helicopter. This allows me to control the mass and its center of mass to my liking.
While it works fine while airborne and does feel like there’s weight to it, if its on the ground and a player tries to climb or stand on it, it starts getting very funky and spazzes out.
This goes away when i set the helicopter’s body to have mass again, but now i no longer have full control over the center of mass which is a problem.
i have already made the cube’s size match the whole helicopter, but that did not work.
Is there a way to be able to control the center of mass while also having the assembly parts be massed? I’m thinking of maybe positioning the cube such that the combined CoM is where i want it to be, but i dont know how to caculate that.
Sounds fancy and complex. You want to prevent the 'copter from getting funky, right? Cant, you just stick it to the ground whenever it lands? or give it a large invisible part that acts like a weighted base. (Worst comes to worst, give it a large(whole copter size) invisible part that prevents the player from touching it.)
Ok, so after some research and testing i managed to create a function that will return the position of a counterbalance with a specific mass needed to get the specified center of mass.
This will help me be able to control the CoM even with other massed parts.
Updates the position of the counterbalance (Green) to make the center of mass match the attachment’s world position (Red shows the assembly center of mass):
Also takes into consideration the mass of the counter balance:
Code:
function GetCounterweightPosition(partTable, counterweightMass, desiredCoM)
-- set initial variables
local a = Vector3.zero
local b = 0
--loops through each part in the table and add its mass and position to the variables
for _, v in pairs(partTable) do
a += v.CFrame.Position * v.Mass
b += v.Mass
end
--caculates needed position given the counter balance mass to achieved the desired center of mass position
local d = (b * desiredCoM)/counterweightMass
local e = a / counterweightMass
local counterPos = d + desiredCoM - e
return counterPos
end
partTable: The able with all the parts you want included in the caculations.
counterweightMass: The mass of the counterbalance part,
desiredCoM: The world position where you want the center of mass to be.