- Home /
Can I make 2d collider at specific angle?
I want to have a ball reflect off of a collider at exactly 45 degree so that the ball moves only up down left or right. The ball is 2d with no gravity or drag and after it bounces off of my colliders, that i've tried to make as close to 45 deg as I can, a few times it starts to move diagonally and messes up everything. Any help is appreciated.
I think it would be best to make your colliders Triggers, so that Unity doesn't try to handle the physics of collision and write your own simple collider script for the ball, that changes the balls direction OnTriggerEnter.
I was thinking of doing that, but I'm not sure how I would tell which direction the ball is hitting the collider from. So I know which way to make the ball move after
I'm not sure of how complex your levels are but you can put multiple colliders on the objects. So for instance if you have a square obstacle you can put 4 colliders, one for each side. Then you can tell which direction the ball has hit. If your scene is complex, then this will probably make things too slow. You could also simply check the direction of the ball, and reverse it on collision.
Another option could be to store the rotation of the colliders. Once your ball collides with them, check the rotation as well as the current cardinal direction of the ball to figure out which cardinal direction to move in next.
Your answer
Follow this Question
Related Questions
Force PolygonCollider2D into a Square or Autofit BoxCollider2D 0 Answers
Scaling colliders up and down over time 1 Answer
Correcting for a collision overlapping too much? 5 Answers
2d rigidbody falling from the collider when it is moved 3 Answers
Moving colliders that are part of a composite collider 1 Answer