Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I slow down C-Frame rotation?

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

2 comments

0

Just increase the waits on lines 9 and 14

0

Rather than making it wait longer before moving, make it move shorter distances each time interval

1 answer

✓ Accepted answer

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

1 comment

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.