#AssemblyLinearVelocity going too high

1 messages · Page 1 of 1 (latest)

placid cairn
#

So when a toss part touches a player its supposed to lightly fling them. But for some reason at random, instead of setting linearvelocity to a certain number, it adds to it instead (what i assume is happening) Heres the code and video of the problem:

local ball = script.Parent
local cd = false

ball.Touched:Connect(function(h)
if cd == false then
local flingcount = 0
if h then
if h.Parent then
if h.Parent:FindFirstChild("HumanoidRootPart") then
cd = true
repeat
flingcount += 1

                    local hrp = h.Parent:FindFirstChild("HumanoidRootPart")
                    h.Parent.Humanoid.Sit = true
                    hrp.AssemblyLinearVelocity += Vector3.new(0, 10, 0)
                    hrp.AssemblyAngularVelocity = Vector3.new(0, 50, 50)
                    
                until flingcount == 1
            end
        end
    end
    flingcount = 0

    wait(0.5)
    cd = false
end

end)

How would I fix this?

silver girder
#
 hrp.AssemblyLinearVelocity += Vector3.new(0, 10, 0)

Using += is going to add 10 to the Y axis of your Vector3 each time it runs. This means that the second time your function runs you will see your AssemblyLinearVelocity at (0, 20, 0) and the 100th time your function runs it will be (0, 1000, 0). This is why you see such erratic behavior in your video!

To get the most consistent results, you will want to consider finding an ideal value to set your LinearVelocity to. In my game, I use 60 times the Mass of the player's character, which can be found by using hrp.AssemblyMass as a good velocity to emmulate a jumping motion, so you would probably want to set it a little higher

placid cairn
#

Ok i think i fixed it