BodyAngularVelocity causing curving in a balls path

It doesn’t always occur, and the curving is more minimal when the travel distance is farther.

How do I prevent this behavior from occurring? I believe the issue is caused by RotVelocity, but I wanted to know if there is an easy solution

1 Like

I think the sudden change in velocity isn’t registering properly for rotvelocity or something. I have figured out that the ball wants to roll towards the closest axis once velocity starts loosing its power. Like I mentioned in a previous post, this curving does not occur when BodyAngularVelocity’s torque prevents the ball from rolling. (Hence why I believe this is a rotvelocity problem)

If you are using a BodyAngularVelocity object to dampen the ball’s rot velocity, it might be working on the axes independently. This can become noticeable when you are rotating slightly on one axis and more on the the other. The smaller axis gets dampened to 0 before the other one does. I am not certain that this is what is occurring, but I’ve seen similar results BodyVelocity objects and BodyPosition objects.

The video really helps find the problem. Thank you for that. You could try using code like this

local DAMPING = .03
while true do
-- Scale down the ball's rotational velocity
ball.RotVelocity = ball.RotVelocity * (1-DAMPING)
-- If ball's movement is too subtle, then stop it.
if ball.Velocity.magnitude < .5 then
ball.RotVelocity = Vector3.new(0,0,0)
ball.Velocity = Vector3.new(0,0,0)
end
wait()
end
1 Like

I tried this code, with and without BodyAngularVelocity. ( wasn’t sure ) It seems to only slow the ball down more abruptly a few seconds after launching.

(the problem) Do you believe this is intended behavior, or could this be a bug that can possibly be solved.

I don’t know much about actual physics, most of this is self taught. I am sure some else here on the dev forums knows how to properly apply damping. But until someone else speaks up, I am going to let you know what I would do.

You could dynamically adjust the damping value based on the speed of the ball so that the damping is smaller at higher speeds and more intense when slowing the ball down. When using this code, it is indented to be used without the BodyAngularVelocity.

local MIN_DAMPING_SPEED = 100
local MIN_DAMPING = .005

local MAX_DAMPING_SPEED = 2
local MAX_DAMPING = .05


while true do

local speed = ball.Velocity.magnitude
local dampingPercent = (speed - MAX_DAMPING_SPEED) / (MIN_DAMPING_SPEED - MAX_DAMPING_SPEED)
local clampedDampingPercent = math.clamp(dampingPercent, 0, 1)
damping = MIN_DAMPING + (MAX_DAMPING - MIN_DAMPING) * dampingPercent

-- Scale down the ball's rotational velocity
ball.RotVelocity = ball.RotVelocity * (1-damping)
-- If ball's movement is too subtle, then stop it.
if ball.Velocity.magnitude < .5 then
ball.RotVelocity = Vector3.new(0,0,0)
ball.Velocity = Vector3.new(0,0,0)
end

wait()
end

If the ball’s speed is closer to MIN_DAMPING_SPEED, then it will use the MIN_DAMPING value to damp.
If the ball’s speed is closer to MAX_DAMPING_SPEED, then it will use the MAX_DAMPING value to damp.
The higher the damping value, the quicker the ball will slow down.

3 Likes

Like VitalWinter said, damping is not friction. Damping is a force proportional to the velocity where friction is constant.

You can simulate friction using a Torque constant in magnitude but opposite to your angular velocity.

Use the “Torque” constraint (see the Constraint tab in studio).

Alternatively you can apply a force on the ball center of mass, which is opposite to its velocity and has constant magnitude. Or if you want to be fancy, at high velocities you can simulate air friction with a force ~v^2.

2 Likes