2D Hitboxes have hitbox larger than actual

Hi, recently i was trying to use some hitboxes to create an environment but the hitboxes work in a weird way.


Even if the hitboxes doesnt touch i cant move forward

Start debugging! I see green collider gizmo line right on your dude… what is that? Press play and just start deleting things from your scene.

If you delete everything and it still doesn’t work, well, it isn’t a collider!

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.

The point is that i should collide with that green invisible gizmo, i put that there just for test, but i can’t get to the point that my character collider and that collider touch

There’s not enough information to help you. We don’t know what the components are, how they’re set-up, what the script is doing that is moving things, how you’re detecting things etc etc.

So, the problem is that i have two hitboxes, one on a simple square sprite, with 2D Box Collider, and the other one on the feets of my char, with a small 2D Box Collider.
When i run towards the square, my char stops running but the 2 colliders dont even touch even if both detect 2 collision in the Inspector

Player components

Square components

Again, that just sounds like a bug. I cannot reach into your computer and tear things apart to find what is happening, so that’s what you must do yourself. Question everything, make a new scene, stand it up, find what the code is doing, find what the player is doing, press pause and move it by dragging it yourself in scene.

Rip tear shred, figure out what is happening… don’t be gentle with your code. Take no prisoners, question everything, rebuild little subsets of what you have until you get it working, or at least find out why it isn’t.

T

The overall size seems to be quite small.
The likely cause is the Default Contact Offset, which is used to stabilize collisions.
You can reduce the offset (Project Settings → Physics2D → Default Contact Offset), but unless you have a strong reason to do so, I recommend adjusting the overall scale so that the player’s size is approximately 1.

1 Like

Thanx i’ll try and i’ll let you know


I tried to enable some gizmoz collision stuff to see and this is the result, tried to change the sizes but nothing change. I can’t understand

How exactly did you change the size?
What are the Size values of the BoxCollider2D?

I have set the scale of the box and the player from the transform and like multiplied by ten (scale x and y set to 10 for the player)

It seems my intention wasn’t clearly conveyed. For now, let’s set that discussion aside and revert the scale value to its original state. To determine if the cause lies with the Default Contact Offset, please try reducing its value and check if that resolves the issue.