- Home /
Only collide with an object from the side
Lets say that we have a box. i can walk with a character on the box without anything happens. but when i walk into the box from one of the two sides, something will happen like the speed get set to 0.
How do i achive this? I use Javascript and its a 2d game with the new features. do i need to add more colliders to the "box" ? if so how can i enter that exact collider if there is more than one, in a script?
How much have you used OnCollisionEnter? Can you write code now so just any hit on a box changes the speed? Have you seen the examples of how to have the box find out what it was hit by?
Once you have that, you might be able to figure out "side hit" for yourself. Or be able to post some code and ask a more specific question.
I actually have found a way, i just make a simple cube turn the nesh collider off and putted a OnCollisionEnter script on it. I then place it at the sides of the sprites. So yeah :P EDIT: Oh and i know how to use OnCollisionEnter but i have had problems using it in 2D.
Your answer
![](https://koobas.hobune.stream/wayback/20220613130522im_/https://answers.unity.com/themes/thub/images/avi.jpg)