How could I easily detect if a ball is moving or stationary with a couple lines of a code?
As mentioned in the reply above, there isn’t really a method you can use to check if a object is moving.
Heres how I’d go about checking if a object is moving.
local Ball = path.to.Ball;
local isMoving = false;
local lastPosition = Ball.Position;
while true do
task.wait();
if Ball.Position ~= lastPosition then
isMoving = true;
else
isMoving = false;
end
lastPosition = Ball.Position;
end
You could also use Part.Velocity. Idk if it’s depreceated if it is use AssemblyLinearVelocity.
Part:GetPropertyChangedSignal("Velocity"):Connect(function()
if Part.Velocity ~= Vector3.new(0, 0, 0) then
-- moving
else
-- not moving
end
end
1 Like