Best way to creat a smooth Vector3 to Vector3 transition loop?

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,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
	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

	Tween_Service:Create(Dynamic_MousePose,tweenInfo,{Value =Camera.CoordinateFrame*Offset}):Play()
	script.Parent:SetPrimaryPartCFrame(,1.5,0),Dynamic_MousePose.Value)*script.Parent.V_Offset.Value*script.Parent.V_Rotation.Value)--"V_Offset" ( and "V_Rotation"(CFrame.Angles) will both change in-game.

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.

I think you’re having the XY Problem here, because this doesn’t seem to be a solution to the scenario you briefly mentioned.

You want A to follow B, but be slightly behind (and catch up if B stops). That’s pretty common, especially for pets and such.

It’s usually solved with springs, not generic tweens. There are plenty of good resources on that topic, as well as open source spring modules.

What are you trying to achieve? We might be able to help more with more information :smile:

I think you can use linear interpolation for this, it’s good performance and smooth transition.

Something like:

local function Lerp(A, B, Alpha)
   return A+(B-A)*Alpha

local Dynamic_MousePose = workspace.D_MPart

    Dynamic_MousePose.Position = Lerp(Dynamic_MousePose.Position, workspace.TestPoint.Position, DT*10)

True, but the second point is constantly moving.

If I don’t loop the tween, the point will move once then won’t update after. (As the second point moves around)

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)

Heh, yeah, probably.

This is just the solution I found worked best for the problem, but I have almost no doubt there are MUCH better ways to do it.

That’s spring movement, like I said. I’ve never heard of an FPS using tweening or lerping for that. This is one of the most common uses of springs.

1 Like

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.

1 Like