[SMART PEOPLE REQUIRED] How could I add speed/velocity everytime a part bounces?

script.Parent.Touched:Connect(function(partTouched)
	print("touched")
	script.Parent.Velocity *= script.Parent.Velocity
end)

literally doesnt print.

could you give an example? this is what i kinda thought of

local lastVelocityPosX
local lastVelocityPosY
local lastVelocityPosZ

while true do
	if script.Parent.Velocity.X > 0 then
	lastVelocityPosX = script.Parent.Velocity.X
	end
	if script.Parent.Velocity.Y > 0 then
	lastVelocityPosY = script.Parent.Velocity.Y
	end
	if script.Parent.Velocity.Z > 0 then
	lastVelocityPosZ = script.Parent.Velocity.Z
	end
	task.wait(.05)
	if lastVelocityPosX < script.Parent.Velocity.X then
		print('Bounced on the X axis')
	end
	if lastVelocityPosY < script.Parent.Velocity.Y then
		print('Bounced on the Y axis')
	end
	if lastVelocityPosZ < script.Parent.Velocity.Z then
		print('Bounced on the Z axis')
	end
end

I didnt want to near enough do it but this is roughly how i would do it. Its all theortical code as im on mobile atm.

local Vel
local Prev
local active = true
local C -- Current
local MinChange = 20 -- this is the number you deem a sudden chage

while active do
    if Prev == nil then -- make sure we dont make error
        Prev = GDBool(Part.Velocity)
        Vel = Part.Velocity
    end
    C = GDBool(Part.Velocity)
    if Prev[1] == C[1] and Prev[2] == C[2] and Prev[3] == C[3] then
    -- no changes
    else
        -- we got a change
          If (Vel - Part.Velocity).Magnitude > MinChange then
      -- This is a bounce!!
          end
    end
    Vel = Part.Velocity
    Prev = GDBool(Vel)
    wait(0.05)
end

local function GDBool(Velocity)
    return {PoN(Velocity.X),PoN(Velocity.Y),PoN(Velocity.Y)}
end
local function PoN(N) -- stands for pos or neg
    if N > 0 then -- greate than 0 so positive
        return true -- true here tells us its positive
    end
    if N < 0 then -- less than 0 so negative
        return false -- tells us its negative
    ens
    if N == 0 then
        return nil -- not positive or negative so leave
    end
end
1 Like

so everything works fine, however there is one problem, the bounces are inaccurate:
this code makes the ball bounce higher after every bounce:

if (Vel - Part.Velocity).Magnitude > MinChange then
			print('Bounced')
			CurrentSpeed += 1
			print(CurrentSpeed)
			if CurrentSpeed <= MaxSpeed then
			Part.Velocity += Part.Velocity * 2.225
			elseif CurrentSpeed >= MaxSpeed then
				print("Past Max")
				Part.Velocity += Part.Velocity * 1
			end

however, sometimes when i test the ball bounces high and sometimes when i test it bounces lower

Part.Velocity += Part.Velocity * 1

This doubles the velocity.

Part.Velocity += Part.Velocity * 2.225

This more than triples the velocity.

Part.Velocity *= 1.5 --When speed less than max.
Part.Velocity *= 0.75 --When speed more than max.

Use calculations like these (you may need to change the numbers).

1 Like

is it possible to limit the max velocity of the part?

Yes, you can use a constraint or just check it with a script when changing velocity

1 Like