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

How do I slow down C-Frame rotation?

Asked by 8 years ago

Hope this isn't a repeat question. I have made this obstacle where you jump onto a swing that moves back and forth, but the swing moves incredibly fast. I'd like it to move about as fast as a hinged swing would move, but I haven't found a way to change the speed.

Here is my script:

while true do --Infinite loop

--Tilt Parent
for i = 1, 19 do --Iterate from numbers 1 to 19
script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0.055,0,0)
wait()
end

wait() --Wait

--Untilt Parent
for i = 1, 19 do --Iterate from numbers 1 to 19
script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(-0.055,0,0)
wait()
end
end
0
Just increase the waits on lines 9 and 14 GoldenPhysics 474 — 8y
0
Rather than making it wait longer before moving, make it move shorter distances each time interval BlackJPI 2658 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

This is how I would handle this:

local partCFrame = script.Parent.CFrame
local swingSpeed = 1
local swingAmplitude = 0.055 -- How far it should swing

local t = 0

while true do
    local delta = wait() -- Wait returns the amount of time it waited
    t = t + delta -- Just keep track of time

    -- Sine function makes perfect graph for this sort of swinging animation
    script.Parent.CFrame = partCFrame * CFrame.fromEulerAnglesXYZ( math.sin( t * swingSpeed ) * swingAmplitude,0,0)
end
0
Thanks for the answer! I fixed the problem myself by multiplying the cframe lines, dividing 0.055 by how many times I multiplied it and adding "wait()" in between some of the lines, but your script makes the swinging looks much better and realistic. AussieBro 5 — 8y
Ad

Answer this question