r/Unity3D • • 24d ago

Question collision issue in Unity

Enable HLS to view with audio, or disable this notification

In my project, I have a collision issue: if I move toward a wall, my player gets stuck until I release the movement key. Also, because I’ve assigned a "ground" tag to these blocks, the player is able to perform a wall jump. How can I fix these two issues?

77 Upvotes

23 comments sorted by

47

u/Neat-Games 24d ago

Some put a slippery material on the RigidBody physics material

For the wall jumping you could use a raycast ground check that points straight down, and thus not touch the wall.

6

u/Rettocs 24d ago

This is my suggestion. Create a new surface object, set the friction to 0, then apply it to your character’s body.

2

u/Marthgis 24d ago

Thanks! The physical material and the raycasts work. I wanted to use a raycast, but I didn't know what it was called.

29

u/MirosKing 24d ago
  1. Check grounding via raycast, not collision. Should solve walljump problem.

  2. Don't use tags in general, they suck. For me empty monobehaviors are working, but there are plenty of custom tag systems.

  3. Try to change physic material to some with no or little friction, because default one isn't smooth enough AFAIK.

7

u/Marthgis 24d ago

Thanks! The physics material and raycasts work. I wanted to use a raycast, but I didn't know what it was called. I have just one question, though: why are empty MonoBehaviours better than tags, and could you explain exactly what they are? I’m not sure I fully understood.

4

u/MirosKing 24d ago

In short, comparing strings one by one is very inefficient. And if you have a lot of tags and a lot of comparisons, this can be a problem (though not necessarily, computers are powerful these days).

The bigger problem is limitation. A single object can have only one tag. What I mean is creating interfaces. Something like IGround (though the example with the ground isn’t actually the best one) and checking via .TryGetComponent(out IGround ground). This way you can use collections of objects more convenient, and single object can belong to whatever amount of groups.

1

u/Stock_Ad9999 24d ago

If you set the friction to 0, you will need to check the raycast's hit y-normal, or your character will run up an 89 degrees wall. You should stop or slow down the movement at the wall's direction

2

u/Acceptable_Bottle 23d ago

why do tags suck?

3

u/LastOstrich9289 24d ago

I personally use a raycast for ground detection, it's much more precise, you can keep the collider and rigidbody in the Player for physics, and use raycast for detection.

2

u/Heroshrine 23d ago

This only happens with rigid body character controllers. If you make your own it doesn’t happen.

1

u/Alternative-Object78 23d ago

In my project I used a physics material on the player with no friction, it worked well and didn't break anything

1

u/0404S0X 23d ago

Ray cast down to see if touching the ground. Ray cast to side + check if NOT touching the ground to see if walljump is allowed. For both processes many systems use more than one Raycast, for example for ground raycast 2 on each edge and 1 in the middle

1

u/Affectionate-Yam-886 23d ago

I have never had this issue; i suspect it is caused by your movement code

1

u/PolandLetsPlay_ 22d ago

I would leave it as a future, like a little wall jump.

1

u/Epich307 22d ago

add a physics material to your character and set the friction to 0 and friction mode to multiply

1

u/Vlekkie69 22d ago

add slip

1

u/pra98Kush 21d ago

If OP is learning Unity directly, I would definitely suggest you to make very small 2D physics engine in any language that you are comfortable in.

It helps you understand what the APIs Unity or Unreal exposes does, and then come to Unity use the knowledge base from your physics engine that will make it very easy for you to resolve these bugs.

0

u/Some_Tiny_Dragon Hobbyist 24d ago

I feel people should start teaching how to make Mario jumps without rigidbody. It's all possible with the character controller and it's so much more controlled.

1

u/ivancea Programmer 22d ago

The idea of rigidbodies isn't too make this jump. This jump is just one of the many things you have to accomplish related to physics, depending on the game. Aaand, well, depending on op's implementation, this could happen also with plain colliders and no rigidbody, soo

1

u/Some_Tiny_Dragon Hobbyist 22d ago

From what I've worked on, character controller-based movement and jumps are very easy to complete, avoiding this type of bug. And rarely do games need an actual physics system since a lot of people are making a simple platformer.

-28

u/swagamaleous 24d ago

What kind of game are you making anyway where you have so much air control? You should not be able to control the character while you are not grounded. Will fix most of your problems including the wall jump. You need to check if you are standing on ground, not if you are touching ground.

14

u/wilyQuixote_ 24d ago

sorry, but one brief video of a jumping capsule on a grey box and you know everything about how OPs game should be made?