Skip to main content
GameDev.net gamedev.net
🔒 Locked

Decelerate Golf Ball

Started by Rhaal Jul 17, 2009 at 1:25 PM 6 replies 4k views
Original Post
Rhaal
Rhaal
I've been working on a 2D Mini-Golf game but I'm getting stuck on decelerating the ball after it's been hit. My research has lead me to this formula: Deceleration = (Original Velocity - Final Velocity) / Time I've plugged this into my code, however I'm confused on a couple things as it's not working properly. 1) Final velocity is zero right? I want the ball to stop. 2) Time: Is this time since the last frame, or time elapsed since the ball was hit? 3) Deceleration: What do I do with the deceleration? Do I multiply the velocity by it? Is the Deceleration the new velocity? I'm having a hard time grasping the concepts. When I tried to do it on my own, I was just subtracting 10% of the current speed, which obviously never got to 0. So can someone explain simply ball-rolling deceleration? I don't care about grass or wind friction. Thanks.
- A momentary maniac with casual delusions.
Raskell
Raskell
Rolling resistance induces a constant force, and thus a constant acceleration (deceleration is just acceleration "in the opposite direction")and can easily be approximated as a constant negative acceleration applied to your ball's velocity over time, which can be a small or large rate depending on the situation.

1) Final velocity will eventually be zero, yes, but this plays no part in your calculations.

2) Time since the last frame, otherwise referred to as delta time (dt).

3) The formula to calculate the force of rolling resistance is F=CrN.
F is rolling resistance force
Cr is Coefficient of rolling resistance
N is normal force (on level surface = mass*gravity)

A formulae for acceleration due to rolling resistance can be derived with a bit of substitution, knowing F = mass*acceleration,
Acceration = CrN/mass

To calculate new velocity every frame subtract Acceleration*dt from current velocity until current velocity = zero.

Just vary Cr for various surfaces to get desired effects. IE the golf green will have low rolling resistances, allowing the ball to roll farther. Fairways will have moderate rolling resistances, and the rough will have high rolling resistances (extreme rough and sand bunkers could have effectively infinite rolling resistance, which just means the ball doesn't roll at all. Velocity = zero the instant it lands)
LessBread
LessBread
Deceleration is negative acceleration. When the ball is hit, acceleration is positive. It can be derived from Newton's formula "force equals mass times acceleration", so divide the force of the strike by the mass of the ball. But that's not the end of the story. Acceleration is a vector too, that is, it has direction as well as magnitude. Direction can be split into components along dimensional axis, up and down, forward and backward, side to side. The up component describes the force pushing the ball straight up, the forward component describes the force pushing the ball forward. The strike on the ball is not the only force acting on the ball. Gravity affects the ball throughout the process, from before it was stuck, through it's flight and after it comes to rest. Gravity points downward. When the ball first takes flight, it's upward component of acceleration is greater than gravity. When it reaches the highest point of flight, the apogee, it's equal to zero ***, when it falls it's equal to gravity, and when it comes to rest it's zero again. Acceleration is the rate of change of velocity. When acceleration is positive, velocity is increasing. When acceleration is zero, velocity is constant. When acceleration is negative, velocity is decreasing.

Check out kinematics, equations of motion and trajectory of projectile at wikipedia.


*** This isn't quite accurate. The total acceleration is zero at the apogee. The upward acceleration of the ball and the downward acceleration of gravity are each equal but pointed in opposite directions so they cancel out. As the ball falls, the upward acceleration is less than gravity, and continues decreasing as the ball descends. Gravity is constant throughout. The forward acceleration on the ball moves the ball forward throughout the arc of travel, impeded by air resistance and wind if there is wind.



[Edited by - LessBread on July 18, 2009 1:40:32 AM]
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
bzroom
bzroom
Quote:
Original post by Raskell
Rolling resistance induces a constant force, and thus a constant acceleration and can easily be approximated as a constant negative acceleration applied to your ball's velocity over time.

Acceration = CrN/mass

To calculate new velocity every frame subtract Acceleration*dt from current velocity.

[Eventually the current velocity will be approximately zero.]


I wish i could thumbs up your post but i can't so i'll just quote it.

For your purposes you can probably consider the Normal force constant, since the ball is not changing in vertical velocity (unless you had ramps and stuff).

One thing you should watch out for is when |Velocity| < Acceleration. You dont want the velocity to start jittering so you should clamp it to zero when it gets close.

Your velocity based resistance method is viscous resistance. It theoretically would never converge at zero as you noticed. You could achieve a "grabbing" effect by implementing coulomb friction and some kind of lower threshold. But evidently rolling resistance, the resistance that exists in your case, is a simple constant decelleration.
fcoelho
fcoelho
Quote:
Original post by LessBreadWhen it reaches the highest point of flight, the apogee, it's equal to zero ***, when it falls it's equal to gravity, and when it comes to rest it's zero again. Acceleration is the rate of change of velocity. When acceleration is positive, velocity is increasing. When acceleration is zero, velocity is constant. When acceleration is negative, velocity is decreasing.

...

*** This isn't quite accurate. The total acceleration is zero at the apogee.

Acceleration is zero *only* when the ball is at rest or in a uniform linear movement. The acceleration of the ball is never zero when it's in free flight, it's equal to (disregarding every other 'environmental effect' such as wind) the gravity, and it's the only force acting on the ball. At the apogee, , but , since there is no force in the horizontal direction.

LessBread
LessBread
Quote:
Original post by fcoelho
Quote:
Original post by LessBreadWhen it reaches the highest point of flight, the apogee, it's equal to zero ***, when it falls it's equal to gravity, and when it comes to rest it's zero again. Acceleration is the rate of change of velocity. When acceleration is positive, velocity is increasing. When acceleration is zero, velocity is constant. When acceleration is negative, velocity is decreasing.

...

*** This isn't quite accurate. The total acceleration is zero at the apogee.

Acceleration is zero *only* when the ball is at rest or in a uniform linear movement. The acceleration of the ball is never zero when it's in free flight, it's equal to (disregarding every other 'environmental effect' such as wind) the gravity, and it's the only force acting on the ball. At the apogee, , but , since there is no force in the horizontal direction.


Yes, you're right the total acceleration at the apogee isn't zero because the ball continues moving forward. I meant the total acceleration along the vertical axis, at the point where the magnitude of upward acceleration equals the magnitude of the downward acceleration due to gravity and the two cancel each other out, where the ball has stopped ascending but has not yet begun to descend.


"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
fcoelho
fcoelho
Quote:
Yes, you're right the total acceleration at the apogee isn't zero because the ball continues moving forward. I meant the total acceleration along the vertical axis, at the point where the magnitude of upward acceleration equals the magnitude of the downward acceleration due to gravity and the two cancel each other out, where the ball has stopped ascending but has not yet begun to descend.

That's not true. The ball keeps moving in the horizontal direction simply because there is nothing preventing it from doing it. You set the initial horizontal and vertical speed of the ball in the first hit, and if there weren't any forces applyed over it, it would be moving forever.

The point is, there is one force, caused by the gravitational field, which causes the object to experience a force given by F=m*a, where a is the acceleration. In this case, the acceleration is caused by gravity, only, and thus the force is F=m*g, g being a vector that is directed approximately to the center of the Earth, or, in programming terms, downwards.

Acceleration is just the variation of linear velocity, nothing more. Don't get me wrong, but I believe you are misinterpreting those terms.
LessBread
LessBread
Quote:
Original post by fcoelho
Quote:
Yes, you're right the total acceleration at the apogee isn't zero because the ball continues moving forward. I meant the total acceleration along the vertical axis, at the point where the magnitude of upward acceleration equals the magnitude of the downward acceleration due to gravity and the two cancel each other out, where the ball has stopped ascending but has not yet begun to descend.

That's not true. The ball keeps moving in the horizontal direction simply because there is nothing preventing it from doing it. You set the initial horizontal and vertical speed of the ball in the first hit, and if there weren't any forces applyed over it, it would be moving forever.

The point is, there is one force, caused by the gravitational field, which causes the object to experience a force given by F=m*a, where a is the acceleration. In this case, the acceleration is caused by gravity, only, and thus the force is F=m*g, g being a vector that is directed approximately to the center of the Earth, or, in programming terms, downwards.

Acceleration is just the variation of linear velocity, nothing more. Don't get me wrong, but I believe you are misinterpreting those terms.


I'm not misinterpreting the terms, I'm imagining that the ball is self-propelled. That would be some ball! You're right, the only acceleration on the ball in flight is gravity. The force applied to propel the ball happens before the ball takes flight, it's not applied at every moment in the arc, which is how I was mistakenly thinking about it and which is why I imagined that the two canceled each other out at the apogee.

"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.