cwd30
(seawead30)
May 1, 2020, 4:30am
#1
I’m making a swing bridge, and I need the bridge to stop rotating once it hits 90 degrees.
It is supposed to start off like this:
and then stop rotating once it reaches this position:
Here’s what I’ve tried so far, it spins the bridge, but doesn’t stop when it hits 90 degrees.
repeat
wait()
script.Parent:SetPrimaryPartCFrame(script.Parent.Primary.CFrame *
CFrame.fromEulerAnglesXYZ(0.002,0,0))
until
script.Parent.Primary.Orientation == CFrame.new(0,-90,-90)
Ra_f
(Raf)
May 1, 2020, 4:42am
#2
As far as I know Orientation takes a Vector3 value, so the following code will never stop
until script.Parent.Primary.Orientation == CFrame.new(0,-90,-90)
What you would instead want to do is (assuming the values above are the end values)
until script.Parent.Primary.Orientation == Vector3.new(0,-90,-90)
cwd30
(seawead30)
May 1, 2020, 4:43am
#3
Is there a way to detect if the orientation is greater than -90?
Something like:
until script.Parent.Primary.Orientation == Vector3.new(0,>=-90,-90)
Because it doesn’t always land on 90 since I’m using the wait() command, it misses it sometimes
Edit: What you put above didn’t work, it still kept going, maybe because it skipped over it.
Orientation.Y? (30 char)…
You should use TweenService it’s much easier and smoother
local tweenService = game:GetService("TweenService")
local tween = tweenService:Create(PrimaryPart,TweenInfo.new(5),{CFrame = PrimaryPart.CFrame * CFrame.Angles(0,math.rad(90),0)}
tween:Play()
1 Like
Ra_f
(Raf)
May 1, 2020, 4:47am
#6
For the sake of readability, Put the Orientation itself in a variable
local orientation = script.Parent.PrimaryPart.Orientation
and then
until orientation.Y >= -90
Also please make sure the bridge itself actually reaches 90 degrees before attempting to check if it’s orientation is larger than or equal to 90 degrees
cwd30
(seawead30)
May 1, 2020, 4:49am
#7
I’m using repeat until, so what it does is it keeps turning until it reaches 90, at least that’s what I think it does.
Ra_f
(Raf)
May 1, 2020, 4:50am
#8
It’s probably better to use TweenService like UniversalScripter mentioned above
cwd30
(seawead30)
May 1, 2020, 4:52am
#9
Hmm, that seemed to return this:
The entire local tween line has a warning (underlined blue).
I’ve never really used TweenService before.
You’re probably dealing with a float precision error. Instead of it being at 90 it’s probably at 89.9999999999 or something like that.
I forgot to add a parentheses at the end , add that and it should work.
Edited Code :
local tweenService = game:GetService("TweenService")
local tween = tweenService:Create(PrimaryPart,TweenInfo.new(5),{CFrame = PrimaryPart.CFrame * CFrame.Angles(0,math.rad(90),0)})
tween:Play()
I’ve tested out the code and it works for me