I want to use a Torque constraint to apply my own force calculated by a spring to reach a desired pitch
Right now I am doing:
local cart--part to rotate
local pitchstab--torque constraint with relativeTo=attachment0 which is at CoM and has local cframe=identity
local pitchspring--calculates force like so: -w*(w*(self.x-self.x1)+d*2*self.v); where w is undamped angular frequency (i set to 7) and d is damping ratio (i set to 1 to critically damp)
local mass=cart:GetMass()
local function angle(v0,v1)--angle from v0 to v1, assumes they are unit
local si=v0:Cross(v1).magnitude
local co=v0:Dot(v1)
return math.atan2(si,co)
end
game:GetService'RunService'.Stepped:Connect(function(dt)
local cf=cart.CFrame
local look--desired global look direction
local targ=cf:inverse()*look
local cross=Vector3.new(0,0,-1):Cross(targ).Unit
pitchspring.x=angle(Vector3.new(0,0,-1),targ)
pitchspring.v=(cf:inverse()*cart.RotVelocity):Dot(cross)
pitchspring.x1=0
pitchstab.Torque=Vector3.new(pitchspring.f*mass,0,0)
end)
This just doesn’t seem to work though, it just makes the cart spin https://streamable.com/cw081
What am I doing wrong? I also don’t really understand what RotVelocity and Torque represent (well I know torque is supposed to be force*distance), so I would really appreciate any insights you can provide, are they axis angles?