Slow down script makes ball fly?

local ball = script.Parent

while task.wait() do
	if ball.AssemblyLinearVelocity.Magnitude > 1 then
		ball.AssemblyLinearVelocity = Vector3.new(ball.AssemblyLinearVelocity.X * .89, ball.AssemblyLinearVelocity.Y, ball.AssemblyLinearVelocity.Z * .89)
	end
end

I made a custom script to deaccelerate a soccer ball. When I apply any kind of upwards velocity the ball floats in the air for a while?? I’m unsure how to solve this but I think it might be something to do with the AssemblyLinearVelocity.Y ?

1 Like

Try using Runservice.Stepped loop or Presimulation instead of task.wait(). Perhaps its the taskscheduler order.

1 Like

Maybe try using different types of velocity constraints such as body/linear velocity.

local RunService = game:GetService("RunService")

local ball = script.Parent

RunService.Stepped:Connect(function(time: number, deltaTime: number)
	if ball.AssemblyLinearVelocity.Magnitude > 1 then
		ball.AssemblyLinearVelocity = Vector3.new(ball.AssemblyLinearVelocity.X * .89, ball.AssemblyLinearVelocity.Y, ball.AssemblyLinearVelocity.Z * .89)
	end
end)

Still doesn’t work.

Have you tried using a BodyGyro?

Using a bodygyro causes the ball to spin to the left/right weirdly, I can send a video if you want to see

local ball = script.Parent

while task.wait() do
	if ball.AssemblyLinearVelocity.Magnitude > 1 then
		ball.AssemblyLinearVelocity = Vector3.new(
			ball.AssemblyLinearVelocity.X * 0.89, 
			ball.AssemblyLinearVelocity.Y * 0.89, 
			ball.AssemblyLinearVelocity.Z * 0.89
		)
	end
end

You need to include the Y component too

Figured it out.

local RunService = game:GetService("RunService")
local Debris = game:GetService("Debris")

local SLOW_MULTIPLIER = .05

local part = script.Parent

RunService.Stepped:Connect(function(time: number, deltaTime: number)
	local assemblyLinearVelocity = part.AssemblyLinearVelocity
	if assemblyLinearVelocity.Magnitude > 10 then
		local slowForce = Instance.new("BodyForce")
		slowForce.Force = Vector3.new(-assemblyLinearVelocity.X * SLOW_MULTIPLIER, 0, -assemblyLinearVelocity.Z * SLOW_MULTIPLIER)
		slowForce.Parent = part
		Debris:AddItem(slowForce, .1)
	end
end)

You can actually just use a bodyForce to slow down the ball and it doesn’t affect the ball’s gravity at all.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.