Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Making a spring, Vector3 expected got a number?

Asked by 4 years ago

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

Log in to vote
0
Answered by
VitroxVox 884 Moderation Voter
4 years ago
Edited 4 years ago

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.

0
I'm trying to pass through numbers, not a Vector3 Thunder878712817 -6 — 4y
Ad

Answer this question