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

Make a less sloppy animation?

Asked by
iNicklas 215 Moderation Voter
8 years ago

Don't mind the scripting, its correct. But the animation is Sloppy. How would i make it more "ongoing"

gui.Parent = player.Character.Head
wait(0.25)
gui.ExtentsOffset = Vector3.new(0,5,0)
wait(0.25)
gui.ExtentsOffset = Vector3.new(0,6,0)
wait(0.25)
gui.ExtentsOffset = Vector3.new(0,7,0)
wait(0.25)
gui.ExtentsOffset = Vector3.new(0,8,0)
wait(4)
gui.Parent = nil

end

3 answers

Log in to vote
1
Answered by
XAXA 1569 Moderation Voter
8 years ago

What you want to use is a Numeric For-Loop

According to the Lua 5.0 documentation (available online)

A numeric for has the following syntax:

for var=exp1,exp2,exp3 do something end

That loop will execute something for each value of var from exp1 to exp2, using exp3 as the step to increment var. This third expression is optional; when absent, Lua assumes one as the step value.

For example, doing

for i=2,10,1 do
    print(i)
end

will print:

2
3
4
5
6
7
8
9
10

Because we are printing i, which starts at 2, and we are also adding 1 to i until we reach 10. Going back to the Lua Documentation:

This third expression is optional; when absent, Lua assumes one as the step value.

This means that we can omit 1 from the for-loop (so it will be for i=2, 10 do)and it will still print the same values.

That's cool and all, but how would I use it?

Given your original script, it looks like you want to smoothly animate the gui from Vector3.new(0,5,0) to Vector3.new(0,8,0) in one second. Four seconds after that, you want to set its Parent to nil. You would execute a for-loop that looks something like this:

gui.Parent = player.Character.Head
--  a wait() is roughly 1/30th of a second. wait() is the shortest pause you can do without using RunService.
for i = 5, 8, 1/30 do
    -- sets ExtentsOffset.Y to i, which is animated from 5 to 8
    gui.ExtentsOffset = Vector3.new(0,i,0)
    wait()
end
gui.ExtentsOffset = Vector3.new(0,8,0)
wait(4)
gui.Parent = nil

Please not that the animation will not take exactly one second, but it should be roughly the same. For animations that take exactly one second, you will have to do delta timing, which is a complex topic outside the scope of this question.

Ad
Log in to vote
0
Answered by 8 years ago

Smaller intervals. Just make it wait less and move less, and it will be less jumpy. It would be a good idea to learn how to use a for loop at this point.

0
Yeah thats what i want to know about, how loops work. iNicklas 215 — 8y
Log in to vote
0
Answered by
iNicklas 215 Moderation Voter
8 years ago
for i=1, 10 do wait(0.25)

gui.ExtentsOffset = Vector3.new(0,4,0)

end

Would this work?

0
Yes that would work. User#6546 35 — 8y
0
Well, it doesn't :(( iNicklas 215 — 8y

Answer this question