Hi,
I am making a Viewmodel and wanted to add Hooks law to it. I then followed @EgoMoose video explaining it. Problem is it doesnt work at all, not a single movement.
Scripts :
Module Script :
local spring = {}
function spring.new(Position, Velocity, Target)
local self = setmetatable({}, {__index = spring})
self.Position = Position;
self.Velocity = Velocity;
self.Target = Target
self.k = 1;
self.friction = 1;
return self
end
function spring:update()
local d = (self.Target - self.Position);
local f = (d * self.k)
self.Velocity = (self.Velocity * ( 1 - self.friction)) + f
self.Position = self.Position + self.Velocity
end
return spring
Local Script :
local Hook = require(game.ReplicatedStorage.WeaponModules.Hook)
Spring = Hook.new(WeaponViewmodel.PrimaryPart.Position, Vector3.new(0, 0, 0), camera.CFrame.LookVector)
Spring.Friction = .1
-- rest of code
RunService.RenderStepped:Connect(function(deltaTime)
if Spring then
Spring.target = camera.CFrame.LookVector
Spring:update()
HookCF = CFrame.new(Spring.Position)
end
-- rest of code again
end)
Thanks you for eventual answers!