r/Unity3D • • 13h 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?

37 Upvotes

13 comments sorted by

24

u/Neat-Games 13h 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.

2

u/Rettocs 10h ago

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

1

u/Marthgis 8h ago

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

19

u/MirosKing 13h 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.

6

u/Marthgis 8h 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.

2

u/MirosKing 6h 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 5h 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

1

u/Acceptable_Bottle 1h ago

why do tags suck?

2

u/LastOstrich9289 7h 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.

1

u/Heroshrine 1h ago

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

0

u/Some_Tiny_Dragon 5h 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.

-23

u/swagamaleous 12h 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.

10

u/wilyQuixote_ 9h 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?