• Question

• If a ball hits a square, how can I learn where the ball hits from? (Right,Left,Up,Down)

The ball has velx and vely and I can check if ball collides with square.

Friday, January 13, 2017 2:11 PM

• Hi,

Not trivial so google the web for the physics and trig geometry.

Using extension there is LDPhysics that used box2D physics engine or LDShapes.Overlap that detects overlap of a circle and square.

To white your own collision detection and bouce physics is more work but a great challenge, maybe start with for basic physics

https://gamedevelopment.tutsplus.com/tutorials/when-worlds-collide-simulating-circle-circle-collisions--gamedev-769

For a ball square collision you will have to first detect an overlap, then which face was hit and then bounce the ball off the face like a ball hitting a wall.  To bounce the square and circle do it in centre of mass reference frame, probably ignore rotational inertia (causing ball and square to spin) initially.

Friday, January 13, 2017 6:52 PM

All replies

• Hi,

Not trivial so google the web for the physics and trig geometry.

Using extension there is LDPhysics that used box2D physics engine or LDShapes.Overlap that detects overlap of a circle and square.

To white your own collision detection and bouce physics is more work but a great challenge, maybe start with for basic physics

https://gamedevelopment.tutsplus.com/tutorials/when-worlds-collide-simulating-circle-circle-collisions--gamedev-769

For a ball square collision you will have to first detect an overlap, then which face was hit and then bounce the ball off the face like a ball hitting a wall.  To bounce the square and circle do it in centre of mass reference frame, probably ignore rotational inertia (causing ball and square to spin) initially.

Friday, January 13, 2017 6:52 PM
• Thanks litdev!

Friday, January 13, 2017 10:51 PM