Unity collider touch not act on player

I have both player and ground with colliders 2D and player is supposed to stop on top of ground but instead it stops at the bottom of the ground.

Code

PlayerController
```csharp
*using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public float moveSpeed;
    private float moveSpeedStore;
    public float speedMultiplier;
    public float speedIncreateMilestone;
    private float speedIncreateMilestoneStore;
    private float speedMilestoneCount;
    private float speedMilestoneCountStore;
    public float jumpForce;
    public float jumpTime;
    private float jumpTimeCounter;
    private bool stoppedJumping;
    private bool canDoubleJump;
    private Rigidbody2D myRigidbody;
    public bool grounded;
    public LayerMask whatIsGround;
    public Transform groundCheck;
    public float groundCheckRadius;
    // private Collider2D myCollider;
    private Animator myAnimator;
    public GameManager theGameManager;
    public AudioSource jumpSound;
    public AudioSource deathSound;

    // Start is called before the first frame update
    void Start()
    {
        myRigidbody = GetComponent<Rigidbody2D>();
        myAnimator = GetComponent<Animator>();

        jumpTimeCounter = jumpTime;
        speedMilestoneCount = speedIncreateMilestone;
        moveSpeedStore = moveSpeed;
        speedMilestoneCountStore = speedMilestoneCount;
        speedIncreateMilestoneStore = speedIncreateMilestone;
        stoppedJumping = true;
    }

    // Update is called once per frame
    void Update()
    {
        grounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, whatIsGround);

        if(transform.position.x > speedMilestoneCount)
        {
            speedMilestoneCount += speedIncreateMilestone;
            speedIncreateMilestone = speedIncreateMilestone * speedMultiplier;
            moveSpeed = moveSpeed * speedMultiplier;
        }

        myRigidbody.velocity = new Vector2(moveSpeed, myRigidbody.velocity.y);

        if(Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0) )
        {
            if(grounded)
            {
                myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpForce);
                stoppedJumping = false;
                jumpSound.Play();
            }

            if(!grounded && canDoubleJump)
            {
                myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpForce);
                jumpTimeCounter = jumpTime;
                stoppedJumping = false;
                canDoubleJump = false;
                jumpSound.Play();
            }
        }

        if((Input.GetKey(KeyCode.Space) || Input.GetMouseButton(0)) && !stoppedJumping)
        {
            if(jumpTimeCounter > 0)
            {
                myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpForce);
                jumpTimeCounter -= Time.deltaTime;
            }
        }

        if(Input.GetKeyUp(KeyCode.Space) || Input.GetMouseButtonUp(0))
        {
            jumpTimeCounter = 0;
            stoppedJumping = true;
        }

        if(grounded)
        {
            jumpTimeCounter = jumpTime;
            canDoubleJump = true;
        }

        myAnimator.SetFloat("Speed", myRigidbody.velocity.x);
        myAnimator.SetBool("Grounded", grounded);
    }

    void OnCollisionEnter2D(Collision2D other) {
        if(other.gameObject.tag == "killbox")
        {
            theGameManager.RestartGame();
            moveSpeed = moveSpeedStore;
            speedMilestoneCount = speedMilestoneCountStore;
            speedIncreateMilestone = speedIncreateMilestoneStore;
            deathSound.Play();
        }
    }
}*

```
Player settings

Question

What should I do to hold my player on top of ground?

Thanks.

Can you see the gizmo for the ground and player? From your image your BoxCollider2D gizmo seems to show you the problem in that it’s way above the player rendering so physics is working fine. Your inspector shows its offset +1m up in Y too.

Hi, thanks for respond. It’s my bad that I haven’t mentioned that I am absolute newbie in unity and unfortunately I have no idea what that gizmo is or where it’s placed.
And regarding to offset Y I’ve also tried 0 and some negative numbers such as -0.91 none changed current behavior.

So would you mind share your knowledge the way that a newbie like me could understand what to do? :smile:

Thanks again.

The gizmo is what is rendered in the scene view to represent the object you’re looking at. Lights have icons, so does the Camera. The 2D colliders have the green outlines you see and you even point to it in your image. For the BoxCollider2D it’s the box shown in your image. As you can see, the box doesn’t align with your player sprite renderer (it’s 1m above it) because you told it to be offset 1m up. When the box rests on the surface, your player is 1m below it, again because you set that offset.

You say you tried zero but that doesn’t seem correct. The reason your at your position is because it’s correct as the BoxCollider2D is resting on the surface. I’m not sure how else to describe it.

Thank for response. Please describe it this way so I can get your point:

  1. should I reposition my player in edit mode?
  2. should I make my offset -1?
    Or something else that I don’t understand?

Set offset to zero. Basically you want the box to cover your sprite renderer. I mean, didn’t you set the offset to (0,1)? Begs the question why you’ve got it set to that.

In the end, I’m only going on the single image of your screen you posted so I cannot tell you exactly what is going wrong. You already said you set the offset to 0 and it “didn’t work” so I have no idea beyond that without more information.

I think I’ve found what cause the issue but not sure how to fix it.

Here is my boxCollider in play mode

6342747--704733--001.png

It’s set to the center of my player object while my player has pivot in bottom-center

Now hoe can I fix that misplaced pivot?

I give up, unity isn’t for me!:frowning: