I have a bouncy ball player, and I have given it the ability to roll up ramps. However, when the ball tries to roll up ramps that are somewhat steep but are still shallow enough to be rolled up, it bounces off the ramp. I do not want this behavior.
The way I tried to solve this was to disable the ball's bounciness when it touches a ramp it can roll up in OnCollisionEnter() and to restore its bounciness in OnCollisionStay(). Unfortunately, this resulted in the ball's bounciness being disabled and restored in the same frame, resulting in it bouncing off the ramp anyway.
What I want to do is disable the bounce, wait for one frame, then restore it, but I cannot find a way to do that. I tried making the following coroutine to do that, but it didn't work (was it because I put it in OnCollisionEnter()?):
void DelayJustDisabledBounceReset()
{
StartCoroutine(DelayJustDisabledBounceResetCoroutine());
IEnumerator DelayJustDisabledBounceResetCoroutine()
{
yield return null;
m_JustDisabledBounce = false;
}
}
So, I have two sets of questions:
- Is disabling bounciness for one frame the right solution? If not, what should I do instead?
- How can I delay resetting the bounciness for one frame?