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

Preventing the springs when moving back and forth(and jumping)?

Asked by 8 years ago

I have springs (hookes law) for more realistic gun movement. When I move back and forth, the part also moves back and forth. I ran this on other people and it doesn't look good on the server, so I want to prevent that on the Z axis, and when I jump, the part also moves up and down, I don't want that either. Anyone have a clue to fix this?

game:GetService("RunService").RenderStepped:connect(function()
    testPart.LocalTransparencyModifier = 0

    local x, y, z = Camera.CFrame:toEulerAnglesXYZ()
    local x2, y2, z2 = lastCamPos:toEulerAnglesXYZ()
    local lastDist = (
        CFrame.new(0, y, 0).p -
        CFrame.new(0, y2, 0).p
    ).magnitude * -2.15


    springee.target = Camera.CFrame * CFrame.new(0, 0, -3).p
    springee:update()

    testPart.CFrame = testPart.CFrame:lerp(CFrame.new(springee.position, springee.position + Camera.CFrame.lookVector) * CFrame.Angles(0, math.rad(lastDist/1.25), math.rad(lastDist)) * Offset, .7)
    lastCamPos = Camera.CFrame
end)

Answer this question