[SOLVED] Realistic Ball spin using physics

My Simple attempt and the issues it causes when trying to get the ball to rotate realistically with the game in regards to spinning.

What I did: In the ball material I enable friction by inputting a number other than zero. This works great in regards to getting the ball to spin the way i want it to spin.

Problem I’m having: Friction is affecting the velocity of the ball, not just the rotation. I do not want this. The spinning is great but the ball slows down over time.

What I tried to resolve the problem: I attempted to use very low numbers for friction and attempted to compensate for the apparent “drag” in velocity by increasing bounce. for instance. Friction = 0.1 Bounce = 1.1 . This almost seems to work perfectly except in instances when there is a lot of bouncing happening - the velocity increases exponentially. In the RigidBody2D inspector, i have linear and Angular Drag set to zero so my assumption is that adding friction will not have an effect on velocity but that doesn’t seem to be the case.

What I need: I need a way to clamp the ball’s velocity OR prevent friction from dampening the velocity. I simple do not understand Mathf.clamp enough to figure out how to do it properly.

I’d like to be able to adjust the clamping in the inspector which I can do with “public float bmaxX, bmaxY;” I just don’t even know where to begin defining the Mathf.clamp variable or statement.

Hello Buddy! You are going to need to monitor your x and y velocity values to prevent them from getting too low or too high. As far as the ball slowing down too much after friction has taken its toll, the velocity is getting too close to zero, whether it be with the x portion of velocity (your horizontal change), or the y, which is vertical change. Making use of the Math.Abs function, you can watch for too much slow down and adjust accordingly with something like this: https://pastebin.com/gFy2LJpv

Preventing the ball from going too fast would require similar code, but you should be able to do it by flipping your greater-than and less-than symbols. Hope this helps!

2 Likes

You’re the best Kelsey! Thanks for sharing this, so glad we’re doing this course together.
(Everyone else:Yep, we’re friends IRL)

EDIT: This effectively prevents the ball from getting too slow from the drag created by using friction on the ball material object.

1 Like