BallShooting Game Issue with Detecting ball stopping when rolling uphill
The Setup
I have a small ball shooting game (think mini golf) There is an aim guide and you press a button to instanly add force to the ball. When the ball starts rolling I turn off the guide. I detect when the ball stops again and bring the guide back.
The Problem:
If the ball goes straigh up a hill when it reaches the apex and starts to turn back there is a brief moment where it stops.
My detection picks this up and turns on the guide again. The detection is all happening in the update step and I know I need to add a delay in the check somewhere but i'm not quite sure how to do it.
** this code is part of a switch case(Rolling) in Update The time check is there to add a miniscule delay so it gives the ball a chance to start moving before it checks to see if it stops.
ballspeed is fed in from another script (ballSpeed = rb_ball.velocity.magnitude; )
When its detected as stopping it switches to the LoseCheck case then back to Aim Case where it enables the guide again
case GameState.Rolling:
if (Time.time > checkTime)
{
if (_ballController.ballSpeed < 0.05f)
{
_ballController.StopBall(); //stops the ball
gameState = GameState.LoseCheck;
}
}
break;
Any help or suggestions appreciated.
Link to: Github Repo
Answer by Sam-Robichaud · Sep 22, 2019 at 12:30 PM
I was able to solve it by using
rigidbody.IsSleeping()
Your answer
Follow this Question
Related Questions
How do I manually change a sliding ball into a rolling ball? 1 Answer
Issue with physic engine 0 Answers
Ball doesn't roll in roll-a-ball for mac 0 Answers
Hit ball with racket 2 Answers
Move 2D ball on any ground 0 Answers