Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I convert this spring physics script from Vector3 to CFrame?

Asked by
Supint 60
9 years ago
dampen=0.5
speed=6
restpos=workspace.Part.Position
pos=restpos
vel=Vector3.new(0,0,100)

while true do
    restpos = workspace.Part.Position
    local dt=wait()/speed
    local accel=restpos-pos-2*dampen*vel
    vel=vel+dt*accel
    pos=pos+dt*vel
    workspace.MovePart.Position = pos
end

This script works nicely (credit to AxisAngle), but only for positioning. It would be nice to know how to use this with CFrames, but the same operators that apply to Vector3 don't always apply to CFrame.

Thus a moderate rewrite is in order. I'm not really sure how to incorporate the rotation matrix.

Answer this question