Hello, I made a ViewModel flashlight item and when somebody turns on the flashlight, it tweens into the frame. The problem with this is that when a player moves the camera or their position, it still tweens in the original position.
I know that I need to somehow incorporate the tween within the loop but I have no idea how to do so.
Flashlight.CFrame = camera.CFrame * CFrame.new(0, -2.5, 0)
local Tween = TS:Create(Flashlight, TweenInfo.new(1.5, Enum.EasingStyle.Back, Enum.EasingDirection.InOut), {CFrame = camera.CFrame * Offset})
Tween:Play()
Tween.Completed:Wait()
FlashlightSway:BindToRenderStep("Flashlight", Enum.RenderPriority.Camera.Value, function()
Part.CFrame = camera.CFrame
local lightAngle = camera.CFrame.Rotation
currentRotation = currentRotation:Lerp(camera.CFrame, dampeningFactor)
Part.CFrame = currentRotation
end)
Tasty_Snicker:
Flashlight.CFrame = camera.CFrame * CFrame.new(0, -2.5, 0)
local Tween = TS:Create(Flashlight, TweenInfo.new(1.5, Enum.EasingStyle.Back, Enum.EasingDirection.InOut), {CFrame = camera.CFrame * Offset})
Tween:Play()
Tween.Completed:Wait()
FlashlightSway:BindToRenderStep("Flashlight", Enum.RenderPriority.Camera.Value, function()
Part.CFrame = camera.CFrame
local lightAngle = camera.CFrame.Rotation
currentRotation = currentRotation:Lerp(camera.CFrame, dampeningFactor)
Part.CFrame = currentRotation
end)
You could try updating the flashlight tween position constantly:
Flashlight.CFrame = camera.CFrame * CFrame.new(0, -2.5, 0)
local PR = game:GetService("RunService").PreRender:Connect(function()
local Tween = TS:Create(Flashlight, TweenInfo.new(1.5, Enum.EasingStyle.Back, Enum.EasingDirection.InOut), {CFrame = camera.CFrame * Offset})
Tween:Play()
end)
local CancelThread = coroutine.create(function()
task.wait(.5) -- whatever time you see fit.
PR:Disconnect()
FlashlightSway:BindToRenderStep("Flashlight", Enum.RenderPriority.Camera.Value, function()
Part.CFrame = camera.CFrame
local lightAngle = camera.CFrame.Rotation
currentRotation = currentRotation:Lerp(camera.CFrame, dampeningFactor)
Part.CFrame = currentRotation
end)
end)
coroutine.resume(CancelThread)
Sorry I am late, what does PreRender do? Or is it self explanitory
KingBlueDash:
Flashlight.CFrame = camera.CFrame * CFrame.new(0, -2.5, 0)
local PR = game:GetService("RunService").PreRender:Connect(function()
local Tween = TS:Create(Flashlight, TweenInfo.new(1.5, Enum.EasingStyle.Back, Enum.EasingDirection.InOut), {CFrame = camera.CFrame * Offset})
Tween:Play()
end)
local CancelThread = coroutine.create(function()
task.wait(.5) -- whatever time you see fit.
PR:Disconnect()
This does not work either. It still plays the tween at the last position
PreRender is the new RenderStepped, i should have explained that beforehand.
The way i fixed was using playing a animation instead of a tween, i’ll do more research and see if tweening can work though.
I used animations and it does work, but now it causes a weird visual bug that jitters into place a few millisecond after the animation loads.
Flashlight.PrimaryPart.CFrame = (camera.CFrame * Offset)
local LoadedAnimation = animationController:LoadAnimation(Animation)
LoadedAnimation:Play()
--LoadedAnimation.Ended:Wait()
FlashlightSway:BindToRenderStep("Flashlight", Enum.RenderPriority.Camera.Value, function()
Part.CFrame = camera.CFrame
local lightAngle = camera.CFrame.Rotation
currentRotation = currentRotation:Lerp(camera.CFrame, dampeningFactor)
Part.CFrame = currentRotation
end)
now this comes down to personal preference but i use Exponential Out, this make the animation instantly play while still being smooth.
Same thing sadly, let me try making a new temporary connection that changes the offset to something lower out of view, then after the animation I just disconnect and use the renderedstepped bind
i’ll have to test my own viewmodel to see why this is happening.
I tried loading the animation with replicated first, still nothing
You could try making a fake transition inside a ViewportFrame and then hide it and show the actual flashlight, don’t know if that’ll work though.
you may be onto something bro!
I hope so. (Character Limit lol)
Preload the animations, this fixed this bug for me many other times.
1 Like
If you say so! (Chjaracter limit!)
Actually this doesn’t work, even when the animation is pre-loaded or loaded it will still have that nanosecond visual bug