Strange Edge Collider Issue (Giff explained)

It could be because i am using a later version of Unity that behaves differently to what Rick was using when he made the tutorial.

I think i have a simple solution. Add an extra collider. Im using a Polygon collider without a trigger to his body like the board. Seems to of solved the problem of him falling through the Edge Collider 2D which is good. Fingers crossed this will work out.

Up to lecture 38. NameSpaces & SceneManagement. If you use this method just make sure the circle collider with the trigger is higher than the additional collider. Plus make circle collider perhaps slightly bigger. Bit of trial and error, tuning and adjusting but yeh it works. I think it was the fact the there was no collider on his body that was causing the problem of him falling through the edge collider.

oh! no ! problem has come back with an added spinning circle of death then Barry again is stuck under the ice. Might be a a problem with my Mac. Time to do a performance checkup.

The additional collider has not worked by the looks of it.

hmmmm if i set the Reload Delay to 0.1 then he is under the ice for a split 2nd then manages to repeat again.

He resetting himself back to the start line under the edge collider as soon as his head/circle collider hits the ground without the CrashDetector script.

Same thing has happened to someone else by the looks of it [BUG] Surface Effector 2D / Trigger Collider 2D - Unity Answers

Are you sure the problem isn’t in the set starting position in the editor or in the code? You could try moving Barry up and see if he still appears under the edge collider. Something I didn’t think before was to check the pivot of the game object, is it in the middle of the sprite?

I tried moving Barry up pivot of game object is in centre, code is same as tutorial

i suppose i could try using a coroutine instead

If the coroutine does not fix the issue, could you please upload your project to GitHub without the Temp and Library folder and share a link to the public repository here? I’d like to take a look into this.

Here is a tutorial video by Brackeys:

https://www.youtube.com/watch?v=qpXxcvS-g3g

I added this but same problem persists

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class CrashDetector : MonoBehaviour
{
    [SerializeField] float loadDelay = 0.5f;

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Ground")
        {
            StartCoroutine("ReloadScene");
        }
    }

    IEnumerator ReloadScene()
    {
        yield return new WaitForSeconds(loadDelay);
        SceneManager.LoadScene(0);
    }
}

I played around with Barrys position settings to try and avoid being returned underneath the edge collider. Problem is the delay is not happening at the position of the trigger event. He returns back to start position but lower down on the y axis immediately regardless of the script

Ok … by re positioning the Level Sprite Shape and then moving Barry i managed to stop him from being re positioned underneath the collider.

Problem is as soon as trigger event occurs Barry immediately starts again then after the amount of delay seconds starts again :thinking: :confused:

ezgif.com-gif-maker(1)

That’s really strange. Maybe you could log his starting position into your console when the level restarts to see if the issue is caused by the code. Make sure the entire body is above the edge collider. For testing purposes, you could move the starting position even higher on the y-axis.

If the issue persists, I’m wondering if the gravity is pulling him down for a brief moment because the colliders get enabled with a short delay, not necessarily because of your code but because of Unity’s mechanics. Rick suspects that his Barry bounces due to the surface effector, so maybe that effector is also causing unexpected effects in your game.

For testing purposes, you could disable Barry’s Rigidbody2D and Collider2D component and enable them during runtime with a short delay when the Barry object gets created (= in his Start method).

Is your repository up to date with your latest tests? If not, it would be great if you could push the changes if possible, so we are working on the same project state.

Thankyou for your help and support on this matter. I can see your team are doing their best.

My reposiory for Snow Boarding was updated last night. I setup my github account a while ago and have done Bens course. My repositorys are all set to SSH. I’m on the ball with all that.

I have tried almost everything in my knowledge and ability to work this out but with no success. It is very frustrating indeed and has broken my flow in learning for a short while. I personally think i have spent long enough on this now and should move on from this perhaps. By all means if your team can get to the the bottom of this and what is causing this problem would be excellent. However there is no point getting stressed out over it. It’s probably a problem on Unity’s side.

One more thing i forgot to mention.

Barry is now re setting above the Edge Collider now. I solved that problem by adjusting the height of the ground then moving Barry accordingly to that height. The problem is what you see in the last Giff i posted. Like you said which is what i suspect. It’s something to do with the surface effector.

I downloaded your project from GitHub and imported it into Unity 2021.1.26f1. The only problem I noticed was the choppy movement, which I fixed by setting “Interpolate” to “Interpolate” in the Rigidbody2D component.

image

The level does not restart twice after I lost.

I would recommend to update Unity and to not use an older version than Rick. If the issue persists, add a Debug.Log to Barry’s Awake method and also to the method which reloads the level. In both cases, log Time.frameCount along with a meaningful message. This way, you’ll see if the level restarts and when it restarts. Maybe you can also figure out why it restarts, for example, because a collision happened and the OnCollision2D or OnTrigger2D methods got called. If one of the collision methods gets called, you could log the name of the “other” game object into your console to figure out with which game object Barry collided.

Perhaps I’m doing something wrong. If you still get the problem in the latest version of Unity (Unity 2021.1.26f1), please let me know what exactly you did, so I will hopefully be able to recreate the problem.

If you use a laptop, plug the power chord in.

1 Like

Thats strange i never saw 2021.1.26f1 Install at the time i started the Snowboarding project. Either it’s just been released, it just was not there in my Unity Hub then or just made mistake.

Well it’s there now i’m just Installing it. Fingers crossed it will solve the problem.

I tried Interpolate a while ago and i didn’t notice any difference.

I will try adding a Debug.Log to Barrys Awake method and to the method that reloads the level with Time.frameCount like you advised if 2021.1.26f1 Install doesn’t solve issue . I will let you know the outcome :sweat_smile:

That version got released yesterday. :slight_smile:

ahh that’s why :smiley: just waiting for game to load 2021.126f1 nearly there fingers crossed

Privacy & Terms