2D Collider Issues with Partial Intersection as Well as Other Physic issues

So I recently started working on a simple 2d side scroller, but I have com across an issue with Rigid Body 2D physics and 2D Colliders.

I have a script for jumping that checks for a standing state in a Collision Layer script. If standing is true then you can jump by keeping the current X velocity of the Rigid Body, and applying a jump speed in place of the y velocity. However, when tested in unity, when the jump button is pressed, the player will lock and place and can no longer move.

The box/sphere Colliders themselves seem to be doing this weird thing where they partially sink into each other; the green lines that indicate the size of the collider isn’t where the colliders “collide”

Here is the code for the jump script:

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

public class Jump : AbstractBehavior
{
    public float jumpSpeed = 200f;

    // Use this for initialization
    void Start ()
    {
       
    }
   
    // Update is called once per frame
    void Update ()
    {
        var canJump =   inputState.GetButtonValue(inputButtons[0]);

        if (collisionState.standing)
        {
            if(canJump)
            {
                OnJump();
            }
        }
    }

    protected virtual void OnJump()
    {
        var vel = body2d.velocity;

        body2d.velocity = new Vector2(body2d.velocity.x, jumpSpeed);
    }
}

This is what I mean by the colliders partially sinking. The red circle is a debug circle for finding the point to check whether the player is standing or not (collision with layer that the ground is in). Any help is appreciated.

It’s very hard to troubleshoot physics problems. The first thing that pops to my mind is to check the scale of things. How big is this floor? how small is the player collider? does the bug happen when the objects are roughly the same size? both small, both large etc.

Another thing to test is the velocity code. Changing a rigidbody’s velocity can introduce bugs (it can be done, but do keep this in mind). So replace that code with a force system and see if it still goes through the floor. Keep it simple, just add a force associated with input and constraint the object rotation.

Have you adjusted the physics settings at all? Edit>Project Settings > Physics 2d

Know that the 2D physics system applies forces to keep colliders separated, these impulse forces modify the velocity to keep things from overlapping. If you overwrite the velocity then you can overwrite the 2D physics solvers attempt to separate the colliders.

Completely ignoring the jump code you provided, it seems that you might want to check that your ‘standing’ state is correct. The box, under the influence of gravity should land on the ground and won’t sink through until your scripts ‘do stuff’. Sounds like you need to isolate them and see exactly what is happening. You have the code here, not us.

Can you not use the ‘IsTouching’ or ‘IsTouchingLayers’ to determine if your touching the ground layer Maybe it’s that, that is at fault?