local module = {}
module.__index = module
function module.new(k, d, initialdirection, targetdirection)
local self = setmetatable({}, module)
self.k = k
self.d = d
self.velocity = Vector3.zero
self.direction = initialdirection
self.targetdirection = targetdirection
return self
end
function isNan(v)
return tostring(v) == "nan, nan, nan";
end;
function module:update(dt)
local x = self.targetdirection - self.direction
local F = self.k * x
if not isNan(x) then
self.velocity = ((self.velocity * (1 - self.d)) + F)
self.direction = self.direction + self.velocity
print(self.direction)
end
return
end
return module
and
task.wait(2.5)
local RunService = game:GetService("RunService")
local SpringMod = require(script.Spring)
local Arrow = workspace.Arrow
local Part = workspace.Part
local Direction = Arrow.CFrame.LookVector
local Wanted = (Part.Position - Arrow.Position).Unit
local k = 0.05
local d = 0.1
local Spring = SpringMod.new(k, d, Direction, Wanted)
local function OnHeartbeat(dt)
Spring.targetdirection = (Part.Position - Arrow.Position).Unit
Spring:update(dt)
Arrow.CFrame = CFrame.new(Arrow.Position, Spring.direction)
return
end
RunService.Heartbeat:Connect(OnHeartbeat)
this is what happens
I have no clue why this happening because I followed egomoose’s tutorial and tried to modify for direction not position but it did not work