Help with springs!

Hello,

I am confused as to why my spring is ‘teleporting’ or ‘jerking’ to a spot then springs to my designated position.
If you didn’t understand what I said above here’s a video of the problem;

Here’s my code;

local Ego_Moose_Spring = require(game.ReplicatedStorage.Configs.EgoMooseSpring)
local angularFrequency = 0.1
local dampingRatio = 1
local spring = Ego_Moose_Spring.new(workspace.CurrentCamera.CFrame.Position, Vector3.new(), workspace.PinkHat.CFrame.Position)

player.CameraMode = Enum.CameraMode.LockFirstPerson
wait(0.5)
runService.RenderStepped:Connect(function(deltaTime)
	spring.target = workspace.PinkHat.CFrame.Position
	workspace.CurrentCamera.CFrame = CFrame.lookAt(workspace.CurrentCamera.CFrame.Position, spring.p)
	spring:Update(deltaTime)
end)

Why does it jump to a random spot then spring to my target?

1 Like

I think it’s because you are doing hat.p and this is constant and it isn’t changing so update will always return the same thing

Can you quote where I did 'hat.p'? I’m struggling to find it.

What you might wanna do is this;

local Ego_Moose_Spring = require(game.ReplicatedStorage.Configs.EgoMooseSpring)
local angularFrequency = 0.1
local dampingRatio = 1
local spring = Ego_Moose_Spring.new(workspace.CurrentCamera.CFrame.Position, Vector3.new(), workspace.PinkHat.CFrame.Position)

spring.target = workspace.CurrentCamera.CFrame
spring:Update(.05)

player.CameraMode = Enum.CameraMode.LockFirstPerson
wait(0.5)
runService.RenderStepped:Connect(function(deltaTime)
	spring.target = workspace.PinkHat.CFrame.Position
	workspace.CurrentCamera.CFrame = CFrame.lookAt(workspace.CurrentCamera.CFrame.Position, spring.p)
	spring:Update(deltaTime)
end)

Unfortunately this still has not solved my problem. I’m assuming what you added was the

spring.target = workspace.CurrentCamera.CFrame
spring:Update(.05)

is that correct?

image

What’s the point of updating this? if pinkhat isn’t moving.

I think I have found the issue when I have the player go into first-person mode for some reason it bugs out the target workspace.CurrentCamera.CFrame.Position. The ‘jumping’ is caused because if I use player.CameraMode = Enum.CameraMode.LockFirstPerson it still thinks the camera position is where it was last at not the now zoomed-in camera.

The only reason is for if some reason the hat is somehow moved while the transition takes place the spring will keep up with the hat and still look at it.