Currently I’m using egomoose’s method for aiming a weapon.
aimCount = aimCount + 1
local current = aimCount
for t = 0, 101, 10 do
if current == aimCount then
RunService.RenderStepped:Wait()
joint.C1 = start:Lerp(goal, t/100)
end
end
However, using RunService.RenderStepped:Wait()
, I run into a problem with FPS unlockers, CFrame lerping is much more faster when FPS is uncapped.
You could make the lerp goal a separate system from your loop. So it’s not defendant of fps.
What you can do is this:
Every loop call this:
local iter = (os.clock() % 1)*100
then replace t with iter
To add to what @AC_Starmarine is getting at, RunService.RenderStepped:Wait()
returns a value describing how long has past since the last frame. This can be used against some constant to determine where along the lerp you should be. Try something like this:
local LERP_TIME = 3 --A constant, in seconds. Can be whatever you want. Define at the highest reasonable scope.
aimCount = aimCount + 1
local current = aimCount
local current_time = 0 --How much time has passed since since the loop started.
while current == aimCount and current_time < LERP_TIME do
current_time += RunService.RenderStepped:Wait() --Adds last frame's time to the count.
joint.C1 = start:Lerp(goal, math.max(current_time/LERP_TIME,1)) --math.max() ensures lerp never overshoots.
end
But this just lerps joint.C1
instantaneously to joint.C0
local offset = ViewModel_Tool.InvisParts.BodyAttach.CFrame:inverse() * ViewModel_Tool.InvisParts.Aim.CFrame
local start = joint.C1
local goal = aiming and joint.C0 * offset or CFrame.new()
local LERP_TIME = 3
aimCount = aimCount + 1
local current = aimCount
local current_time = 0
while current == aimCount and current_time < LERP_TIME do
current_time += RunService.RenderStepped:Wait()
joint.C1 = start:Lerp(goal, math.max(current_time/LERP_TIME,1))
end
Could you elaborate on what you mean?
Currently this has the exact same results as the original code.
aimCount = aimCount + 1
local current = aimCount
local iter = (os.clock() % 1)*100
for iter = 0, 101, 10 do
if current == aimCount then
RunService.RenderStepped:Wait()
joint.C1 = start:Lerp(goal, iter/100)
end
end
do it every iteration of the loop right before you set the joint cframe.
I’m sorry but I’m gonna need you to explain what you mean.
Do what every iteration of the loop?
put the iter variable script into the line before you set the cframe.
aimCount = aimCount + 1
local current = aimCount
for t = 0, 101, 10 do
if current == aimCount then
RunService.RenderStepped:Wait()
local iter = (os.clock() % 1)*100
joint.C1 = start:Lerp(goal, iter/100)
end
end
https://gyazo.com/3280ba38ebf3179b98d11488eeb81c34
Except now it doesn’t properly lerp the cframe to its goal?
Bumping the post, open for any answers
You’re absolute right. I got my logic flipped on math.max
. It should have been math.min
so that it would use the lerped amount as long as it did not exceed 100%.
1 Like