So, my question is this: What’s the best way to smoothly transition a Vector3 value, into another Vector3 value on an infinite loop? (Another way to describe it might be “Matching the one Vector3 to another, with a delay”?)
The way I’ve tried is with a loop of tweening, which isn’t super performance friendly, and just seems like a not so great way to do it.
Here’s an updated example:
local Camera =workspace.CurrentCamera
local Render_Stepped =game:GetService("RunService").RenderStepped
local Offset =Vector3.new(0,0,-20)--This value will not change, it's only purpose is to stiffen the delayed movement by moving the end point back
local Tween_Service =game:GetService("TweenService")
local tweenInfo =TweenInfo.new(
0.1, --Time
Enum.EasingStyle.Sine, --EasingStyle
Enum.EasingDirection.Out, --EasingDirection
-1, --RepeatCount (when less than zero the tween will loop indefinitely)
false, --Reverses (tween will reverse once reaching it's goal)
0 --DelayTime
)
local Dynamic_MousePose =script.D_MPoint--A Vector3 Value
local PL_Head =script.Parent.Parent.character.Torso--Not actually using the head
Render_Stepped:connect(function()
Tween_Service:Create(Dynamic_MousePose,tweenInfo,{Value =Camera.CoordinateFrame*Offset}):Play()
script.Parent:SetPrimaryPartCFrame(CFrame.new(PL_Head.CFrame.Position+Vector3.new(0,1.5,0),Dynamic_MousePose.Value)*script.Parent.V_Offset.Value*script.Parent.V_Rotation.Value)--"V_Offset" (CFrame.new) and "V_Rotation"(CFrame.Angles) will both change in-game.
end)
The desired outcome, is the Vector3 (position in this case) transitioning into another Vector3 as smoothly as possible, updating and moving properly when the goal Vector3 changes.
Although this code does do that, I’m sure there must be a better way, I just have no idea what that is…
Any help or tips you can share would be greatly appreciated. Thanks.
I don’t really understand, but removing the loop does the tween nevertheless, because the loop does nothing as once you get the the desired spot you wouldn’t move it again.
local function Lerp(A, B, Alpha)
return A+(B-A)*Alpha
end
local Dynamic_MousePose = workspace.D_MPart
game:GetService("RunService").RenderStepped:Connect(function(DT)
Dynamic_MousePose.Position = Lerp(Dynamic_MousePose.Position, workspace.TestPoint.Position, DT*10)
end)
I’m trying to achieve the weigh movement effect common in most FPS.
Where the weapon your holding moves slightly slower then your camera as you look around.
Using a point that updates to the center of the screen, with a delay, was the best way I could think of to achieve this.
(The gun points to this point moving around after the camera)
Can confirm that PF uses springs (it’s pretty obvious if you watch closely). If you look in CorePackages, the Otter library is really good for it, and so is Fraktality’s spr module.