#Keeping a bouncy object from bouncing off certain colliders for one frame

1 messages · Page 1 of 1 (latest)

lone salmon
#

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?
leaden gust
#

Also "waiting one frame" in physics terms should be yield return new WaitForFixedUpdate();

lone salmon
leaden gust
#

Anyway isn't OnCollisionEnter too late for this anyway?

#

By the time that runs you've already bounced, no?

#

Probably you want to use SphereCast to detect before you hit the ramp

lone salmon
#

Sorry, I should have elaborated - m_JustDisabledBounce is a boolean I use to control when I call a function I made that toggles the PhysicsMaterial's bounciness

leaden gust
#

unless it's a property, the material will change "later" but when that "later" is, isn't clear to me without seeing the full script

lone salmon
#

Good point
I left my computer a bit ago - when I get back, I'll post all the relevant code here and then perhaps you (assuming you're available then) can see what the problem is

leaden gust
#

I mean I already feel like this approach has a problem in that OnCollisionEnter is already too late.

lone salmon
#

I know I'm late, but I've decided to experiment with SphereCast-ing
I will come back when I have finished with that

lone salmon
#

Alright, I have changed my approach so that it doesn't rely on OnCollisionEnter() to determine if I will hit something
I now use a SphereCast, but I'm having trouble getting it working
In its current state, it seems to be properly detecting if a slope is ahead but still doesn't prevent bouncing off ramps the player can ascend
I hate to post a bunch of code and ask "what's wrong", but I wouldn't do it if I knew a better way to approach this problem...
https://docs.google.com/document/d/1HfjR2ZK_tP2Rj3l-V4gH_nm3_ttXQemiDfsf3cIjPH0/view

leaden gust
#

!code

summer minnowBOT
leaden gust
#

Google Docs for code is 🤮