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

Why won't the puck bounce off the wall?

Asked by 4 years ago

I'm trying to make a collision script where if a puck hits the wall, it goes the opposite direction. However, it's not even doing that. Here is the script:

local touched = true
local puck = workspace.Puck.BodyVelocity.Velocity
local X = puck.X
local Y = puck.Y
local Z = puck.Z

script.Parent.Touched:Connect(function(part)
    if touched then
        if part.Name == "Puck" then
            puck = Vector3.new(-X, Y, Z)
        end
    end

    touched = false
    wait(1)
    touched = true
end)
0
Try playing with body forces NickIsANuke 217 — 4y
0
did you put a clickdetector you_success -50 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

You wrote down that puck was equal to the puck's velocity as a variable. This would set the variable's velocity to (-X, Y, Z), but not the puck's velocity. Try this:

local debounce = false
local puck = workspace.Puck.BodyVelocity
local X = puck.X
local Y = puck.Y
local Z = puck.Z

script.Parent.Touched:Connect(function(part)
    if part then
        debounce = false

            if part.Name == "Puck" then
            puck.Velocity = Vector3.new(-X, Y, Z)
        end

        wait(1)
        debounce = true
    end
end)
Ad

Answer this question