For my game, I’m currently implementing aerial physics, and with the current method, it would have a linearVelocity for each wing, and by calculating drag, thrust and lift for the wing, it would modify the direction and magnitude of that linearVelocity as needed.
But I think it would be better to have 1 linearVelocity and 1 angularVelocity in the centerofMass of the aeroplane. But how do I calculate the final linearVelocity and angularVelocity values?
(1 miniute drawing to sorta visualize what i need)
aLine and bLine reffer to linearVelocities on part A, both on opposite sides on their part.
cLine and cTorq reffer to a linearVelocity and a torque on part B.
Theoretically these parts should be in sync, but they aren’t. How do I propertly calculate torque?
The angular velocity is equal to the tangential linear velocity (the two linear velocities perpendicular to the radius you applied to the part) divided by the radius of the spin (In this case, the part’s size on the circle’s axis)
From the formula v = ω * r, in which ω is the angular velocity, v is the tangential velocity (sum of the two velocities you applied to the part), and r is the distance from the pivot (center of the part), we can get ω (the angular velocity)
That’s how you get the angular velocity from the linear velocities you applied to it.
Now, how does that work in code?
Code:
This text will be hidden
--Some variables:
local folder = script.Parent
local angularVelPart = folder:WaitForChild("Part0")
local linearVelPart = folder:WaitForChild("Part1")
local attachments : {Attachment} = {
linearVelPart:WaitForChild("Attachment0");
linearVelPart:WaitForChild("Attachment1");
}
local linearVelocities : {LinearVelocity} = {
linearVelPart:WaitForChild("Vel0");
linearVelPart:WaitForChild("Vel1");
}
local angularVelocityObj : AngularVelocity = angularVelPart:WaitForChild("AngularVelocity")
local radiusAxis = "X" --The axis of the radius
--Function:
local function adjustAngularVelocity()
local resultantVelocity = linearVelocities[1].VectorVelocity + linearVelocities[2].VectorVelocity -- Sum of the two vector velocities:
local radius = linearVelPart.Size[radiusAxis]/2 --Calculating the radius (distance from pivot/center)
local angularVelocity = (resultantVelocity/radius) --Calculating ω, the angular velocity
angularVelocityObj.AngularVelocity = angularVelocity --Applying it to the part
end
adjustAngularVelocity()
linearVelocities[1].Changed:Connect(adjustAngularVelocity)
linearVelocities[2].Changed:Connect(adjustAngularVelocity)
Of course, you’ll have to mess with the attachments rotation to make sure the part is rotation on the right axis, but that’s pretty much how it’s done.
Now for torque, you would be right if instead of the velocities you put the forces applied on the part, and if the position was indeed the position relative to the pivot point (center of the part).
The torque is equal to the cross product of the position relative to the pivot point, and the resultant force.
This means that if you have two forces in the same direction, the resultant force would be their sum, and the torque would be the cross product of the resultant force times the radius/position vector (position relative to the pivot)
How it works in code:
--Some variables:
local folder = script.Parent
local torquePart = folder:WaitForChild("Part0")
local vectorForcePart = folder:WaitForChild("Part1")
local attachments : {Attachment} = {
vectorForcePart:WaitForChild("Attachment0");
vectorForcePart:WaitForChild("Attachment1");
}
local forces : {VectorForce} = {
vectorForcePart:WaitForChild("Force0");
vectorForcePart:WaitForChild("Force1");
}
local torqueObj : Torque = torquePart:WaitForChild("Torque")
local distFromPivotPoint = Vector3.new(0,0,torquePart.Size.X/2) --The position/radius vector
local function adjustTorque()
local resultantForceOnForcePart = forces[1].Force + forces[2].Force --Calculate the sum of the two forces
local torque = distFromPivotPoint:Cross(resultantForceOnForcePart) --Calculate the torque from position/radius and resultant force
torqueObj.Torque = torque
end
adjustTorque()
forces[1].Changed:Connect(adjustTorque)
forces[2].Changed:Connect(adjustTorque)
I've put everything in a file for you to try, there are two folders, one for the forces and torque and one for the velocities (angular and linear)
how do i also get the VectorForce of the part with the Torque? Since it is meant for an aerocraft, the multiple panel forces will generate Lift and Drag as well as torque.
Nah, I mean that the plane would both have Torque and VectorForce values, for example if both sides of the forces of the wings for example are opposite to each other, it means the total VectorForce is (0, 0, 0), where the aeroplane only spins and does not accelerate.
So when given a table containing the Force’s Vector3 from the origin of the plane and the Vector3 of the Force itself, the function would return the torque and force of the plane.
As show in the picture below, each wing is defined by two Vector3’s, one for center of the wing’s relative distance from center of the aerocraft, and one for the wing’s edge. And if all pannels produce an equal lift, there would be no net torque and total lift would be positive. But when one side of the aerocraft has a lift of 2, whilst the other one has a lift of 1, there would be a net torque but also a net lift, but how do i calculate net lift?