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

What is the "best" way to slide a part smoothly?

Asked by 8 years ago

In a nutshell: How would I smoothly transition a part between two points efficiently?

Long version: I am creating a game in which there are "cutscenes," in which the camera is attached to a part that moves. Using my limited knowledge, I have attached the camera and I can slide the part in any direction using CFrame. I have, however, run into a wall of problems. Either the sliding is not smooth enough when the wait(#) is too long, or it is not consistent due to it being shorter than Roblox runs. In other words, it is not always the same distance moved when using wait(). As the cutscenes need to be precise, I need to be able to measure and control the distance that the part moves.

How would I ensure that the part moves smoothly and consistently, without slowing the game down due to intense resource usage? Is there a better way to move the part than CFrame?

Oh, in case you want to see what I have right now, here is my script inside the part:

part = script.Parent

--uses current position to start at
posx = script.Parent.Position.X
posy = script.Parent.Position.Y
posz = script.Parent.Position.Z
timer = script.Parent.Timer

wait(1)

while timer.Value <= 5 do --change to time that camera should be moving
    part.CFrame = CFrame.new(posx,posy,posz)
    posx = posx + 0.25
    wait(0.05)
end

"timer" refers to a NumberValue inside the part, it also has a script inside that changes the value every second. This is how I currently measure time inside the game, because although I know there are better methods, I do not know what those are.

Also, the part sliding is not only for cutscenes, I plan on using it for sliding doors as well, so please don't give me an answer that involves directly changing the camera position.

2 answers

Log in to vote
0
Answered by 8 years ago

This is a simple fix.. Let me help

Try this for a starter..


p=Instance.new('Part', game.Workspace) p.Anchored=true for i = 1,math.huge,0.5 do wait() -- Change the 0.5 for the speed ;) :) p.Position = p.Position + Vector3.new(0,0,0.1) end

Hope this helped you!

-BloxSimple

Ad
Log in to vote
-2
Answered by 8 years ago

Since you're using CFrame I would recommend lerp. CFrame.new(0,0,0):lerp(finalCF, percentageToComplete) 1 would be full 0 would be none .5 would be halfway

0
Partially correct answer, bad explanation. -1. evaera 8028 — 8y
0
-.- PureConcept 0 — 8y

Answer this question