OnTrigger but for Intersections and not just touching?

Hi!

first of all, sorry as I can’t really word what I want very well… but please look on the attached photo, my player(the red box) is climbing on the ladder(the green one) even tho he’s just touching the side of it and not intersecting with it… there are many more areas where this happens in my actual game, it is a 2D Side Scrolling platformer.

how can I fix that without adjusting the BoxCollider2D? is there any way to make OnTrigger happen only on Intersections or is my only option to change the BoxCollider2D’s settings?

Thanks!

maybe with some booleans and other checks ?

no idea, if this will work

bool isClimbing, isNearLadder;
    GameObject ladder;
    float shortDistance;
    private void Update()
    {
        if (isNearLadder && !isClimbing)
        {
//or should it be Matf.Abs - Mathf.Abs ? I mean, calculate distance between player and ladder
//maybe 
//Vector2 dist = ladder.transform.position - ladder.transform.position;
//distance = Mathf.Abs (dist.x);
            if (Mathf.Abs (ladder.transform.position.x - ladder.transform.position.x) < shortDistance)
            {
                isClimbing = true;
                //do something
            }
        }
    }
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Ladder") && !isNearLadder)
        {
            isNearLadder = true;
            ladder = other.gameObject;
        }
    }

    private void OnTriggerExit2D(Collider2D other)
    {
        if (other.CompareTag("Ladder") && isNearLadder)
        {
            isNearLadder = false;
            isClimbing = false;
        }
    }
1 Like

not really what I’m looking for, but thanks! :slight_smile:
I might just decrease the size of the hitbox for now I guess…

My question is: The white box part of your ladder or is this a wall or floor item?

If the white box is something separate you might be able to use something like a Psychics2D Material and add it to everything you don’t want there to be friction on. Also offers the ability to add bounciness if so desired. You add the material to your white box and any object you do not wish for the player to stick to.