Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Making a spring, Vector3 expected got a number?

I've been creating a spring and when I call it, it keeps telling me it expects a vector3 which doesn't make any sense. Any help would be nice. It shouldn't need a Vector3 for it

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) -- Error here
    local f = d*self.k
    self.velocity = (self.velocity * (1-self.friction)) + f
    self.position = self.position + self.velocity
end

return spring

1 answer

Here you go i think this should work:

local spring = {}


function spring.new(position,velocity,target)
    local self = setmetatable({},{__index = spring})

    self.position = vector3.new(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) -- Error here
    local f = d*self.k
    self.velocity = (self.velocity * (1-self.friction)) + f
    self.position = self.position + self.velocity
end

return spring

Cause positions are always are said in vectors.

1 comment

0

I'm trying to pass through numbers, not a Vector3

This discussion is preserved as it was. New answers, comments, and votes are closed.