Check side of collision

Godot Version



Hi everyone. I decided to make a arcanoid-type game to practice some game mechanics. I already have a ball, a platform, and bricks. It’s ok about ball touching a top or bottom of brick, I just reverse Y-axis. But things come more interesting then i decided to make a “side” collision from left and right of brick. Every element of a game is simple, it’s just mesh and collision shape. Ball is an Area2D, which emit signal about collision with any object.
Problem is that ball don’t know sizes and scale of brick, so I can’t calculate from which side collision happens. Are there any solutions about this problem?
P.S. I dont want to add another areas or collisionShapes to elements, I search for mathematical solution.

It could be easy to explain it with squared brick. With square i can normalize diff between positions of brick and ball and see, which side was collided. But I didnt see how to do it with scaled brick, then i dont know scale for each axis

Why not use CharacterBody2D instead of Area2D?

After calling move_and_slide() you can get all necessary collision info from it, including the collision normal which is exactly what you need. Using the same normal you can also very easily bounce the velocity vector of the ball.

That’s exactly that I needed. Great thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.