Moving part like Jailbreak Lasers?

So I have this spotlight (cylinder part) I want it to move back and fourth (Just like Jailbreak).
But its just lerping back and forth. Just its lerping fast and it doesn’t stop. But in Jailbreak, it suppose to stop for a short second (under than 1 second). Because in jailbreak, in the museum, the lasers move slower when they reached the finish point then stops less than a second. Hmm, if theres a way of doing it similar to jailbreak…

The video of it lerping:

The problem is, it is lerping fast and not stopping. I want it to move like jailbreak. Is there a way of doing the lerping like in Jailbreak? HELP!! Since the museum was added in jailbreak, the lasers where smoothly lerping back and forth. Hmm, does it use bodymovers or just a script?

I’ve tried looking for some videos but its not the best method. I tried their tutorials but it didn’t seem to lerp like jailbreak. I am not trying to copy, just needing to know how it was done.

THE LERP SCRIPT:

local startpart = script.Parent.Spotlight
local start = script.Parent.Start
local approachingpart = script.Parent.Finish

local startcf = start.CFrame
local endcf = approachingpart.CFrame


-- The Lerp Thing
while true do
	wait()
	-- Forward
	for per = 0.05, 1.00, wait() do 
	   startpart.CFrame = startcf:lerp(endcf, per)
	   wait()
	end	
	-- Lerp Back
	for per = 0.05, 1.00, wait() do 
	   startpart.CFrame = endcf:lerp(startcf, per)
	   wait()
	end	
end

Please do not criticise me! I’m not trying to copy Jailbreak, just needed to know that how it was done by Jailbreak. If any of you know any ways of lerping it like jailbreak, reply below. Any suggestions that I should put into the code, tell me. Any questions? Reply below.

2 Likes

use tween, its much easier…

1 Like

I don’t know much of tweening. I know Jailbreak use lerping to move the lasers.

that doesnt mean, that you cant use tween

1 Like

Maybe I can use tween. But it requires much things. But I could give it a try. Plus TweenService is kinda complex. its complicated for me to do.

what, to tween you just need to enter dictionary with goal like

local goal = {CFrame=endcf}

and tween info like

local info = TweenInfo.new ( number time, Enum easingStyle, Enum easingDirection)

so its easyer than lerping, just dont panic and try new things

1 Like

A Tween Script would look like this:

local TService = game:GetService("TweenService")
local tinfo = TweenInfo.new(5) -- time in seconds
local goal1 = {Position = Vector3.new(x,y,z)}
local goal2 = {Position = Vector3.new(x,y,z)}
local tween1 = TService:Create(yourPart,tinfo,goal1)
local tween1 = TService:Create(yourPart2,tinfo,goal2)

while true do
    tween1:Play()
    wait(6)  -- wait time tween needs + 1 second
    tween2:Play()
    wait(6) -- wait time tween needs + 1 second
end

Note: This script isn’t tested!

1 Like

Then TService:Create(something):Play()?

yes, but better is to do

local tween = --tween creating
tween:Play()

so you can bind events to it,…

The sine (or cosine) functions are your friends!


.
Let’s stretch and translate sine so it fits totally in the positive between zero and 1:
0.5 * math.sin( x ) + 0.5

.
Okay and then we want to translate it so that we get the full path from 0 to 1 and back again in 180 degrees (or 2π radians):
0.5 * math.sin( x - math.pi / 2) + 0.5

.
Then combine it all into your loop:

local speed = 0.1 -- cycles per second
while true do
    for deg = 0, 360, 1 do 
        local per = 0.5 * math.sin( math.rad( deg - 90 ) ) + 0.5
        startpart.CFrame = startcf:lerp(endcf, per)
        wait( 1 / ( 360 * speed ) )
    end	
end

The curve on the graph as it gets close to each peak and trough slow the laser down and ease into the other direction.

This is essentially what Tween’s easing behaviour is specifying. In this example, Sine, but there are also Quad, Quint, and a few other easing functions. They’re each fairly easy to implement manually as shown above if you don’t want to use Tweening, though Tweening will fix any jumpiness for the clients, as Tweens are evaluated clientside for all clients.

7 Likes

@BanTech’s way might be the better one.

1 Like

Thanks! I would try this! This might lerp the same as jailbreak.

IT WORKS! THANKS SO MUCH! IT JUST LERPS LIKE JAILBREAK :smiley:

Plus I have a question: when i click run in studio or join, I want it to lerp without a delay. How would I do it?

That depends what you mean by delay. It’s difficult to ensure the laser is in the same place for every client unless you do the code on the server, so you have to choose between doing the code on the client and knowing that the laser position for one player will be different for another, or you keep it on the server and accept a little bit of latency.

It depends on what the lasers do and whether all players need it to be in exactly the same spot at the same time or not.

2 Likes

I would say use TweenService

1 Like

TweenSerice is a service that makes objects move smoothly and from my knowledge more performance friendly than using loops to move objects.


To create a tween you will first need set up your variables. One of them is the TweenService and the other is the part that you want to tween.

local TweenService = game:GetService("TweenService")
local Part = workspace.Part

The next thing you need to do is set up your TweenInfo as shown below. The TweenInfo is all the information about the tween like how long you want the tween to take, the delay between each tween or how many times you want the tween to repeat. The way you set up the TweenInfo is by calling TweenInfo.new. In the example below I have assigned TweenInfo.new to a variable so that I can use it later:

local tweenInfo = TweenInfo.new(
	10, -- How long the tween takes
	Enum.EasingStyle.Linear, -- The easing style
	Enum.EasingDirection.InOut, -- The easing direction
	-1, -- How many times you want the tween to repeat. If -1 it will repeat forever.
	true, -- Reverse. 
	2 -- Delay
)

The next thing you want to do is actually set up the tween. You can do this by doing TweenService:Create. This function has 3 parameters, one being the object you want to tween, one being the TweenInfo we created earlier and the other being what properties in the object you want to tween. You can see this in the code below:

local Tween = TweenService:Create(
	Part, -- The object you want to tween
	tweenInfo, -- The Tween info
	{Position = Vector3.new(20,20,20)} -- What properties you want to tween. This is where you want the part to end up.
)

With the code at the moment the tween wont play because we haven’t told it to. You need to call the Tween:Play function on the tween to make it play. You can also call more functions on the tween like Tween:Pause to pause the tween or Tween:Cancel to cancel the tween. This can all be seen in the code below:

Tween:Play() -- Used to play the tween.
Tween:Pause() -- Used to pause the tween.
Tween:Cancel() -- Used to cancel the tween.

Here is the full code:

local TweenService = game:GetService("TweenService")
local Part = workspace.Part

local tweenInfo = TweenInfo.new(
	10, -- How long the tween takes
	Enum.EasingStyle.Linear, -- The easing style
	Enum.EasingDirection.InOut, -- The easing direction
	-1, -- How many times you want the tween to repeat. If -1 it will repeat forever.
	true, -- Reverse. 
	2 -- Delay
)
	
local Tween = TweenService:Create(
	Part, -- The object you want to tween
	tweenInfo, -- The Tween info
	{Position = Vector3.new(20,20,20)} -- What properties you want to tween.
)

Tween:Play() -- Used to play the tween.
Tween:Pause() -- Used to pause the tween.
Tween:Cancel() -- Used to cancel the tween.
2 Likes

Swap Linear for Sine to get the effect you wanted @MichaelProductions01. It implements a similar code to the one I gave you for the Sine wave.

3 Likes

Try that:

– The Lerp Thing
while true do
wait()
– Forward
for per = 0.05, 1.00, wait() do
startpart.CFrame = startcf:lerp(endcf, per)
wait(5)
end
– Lerp Back
for per = 0.05, 1.00, wait() do
startpart.CFrame = endcf:lerp(startcf, per)
wait(5)
end
end

1 Like

@BanTech I mean when i click run to test it. It somehow has a 1 second delay before lerping back and forth.

Is that a problem? You’ll always have delay like that when the server and client are starting up. By the time anyone in your map gets to the lasers they will be moving. The server will have started several seconds before the client joins in a live server so you won’t ever see that.

1 Like