# Ideal collisions with borders SOLVED

#### Petrik33

##### Member
Hello everyone, actually I am a newbie in programming physics, so I need help with setting up proper and ideal collisions between my circles and borders, So to understand it clearer without screenshot(will add it soon) imagine a Box with coin in it(2D) and I need to set up collisions of this coin with box borders. Help me please.

#### zendraw

##### Member
you simply check for place_meeting on the left/right up/down and repell coin if it collides, also you can clamp the coin to stay in the box

#### Alexx

##### Member
You could also add some spin to the coin that affects the returning angle.

#### Petrik33

##### Member
you simply check for place_meeting on the left/right up/down and repell coin if it collides, also you can clamp the coin to stay in the box
Thanks a lot, but isn't it just one line of code like if(place_meeting(x,y, border))?

#### Petrik33

##### Member
You could also add some spin to the coin that affects the returning angle.
That's a great idea, but can't understand how it's done?

#### zendraw

##### Member
you have to do that check for all 4 sides.

#### Alexx

##### Member
With regards to the spin and using that to alter the angle slightly.
One approach:
Use a variable, perhaps clamped between -5 and 5.
When calculating a bounce of a side, apply this value to the bounce angle.

Like @zendraw said, check for each side.
Probably need tweeking to detemine from which direction the ball has can from.

Doable in only a few lines of code.

#### Petrik33

##### Member
With regards to the spin and using that to alter the angle slightly.
One approach:
Use a variable, perhaps clamped between -5 and 5.
When calculating a bounce of a side, apply this value to the bounce angle.

Like @zendraw said, check for each side.
Probably need tweeking to detemine from which direction the ball has can from.

Doable in only a few lines of code.
Thank you very much. Actually my code seems to be pretty right then but some ocassions still ocur in situaltions like on screenshots below

#### Attachments

• 42.3 KB Views: 4
• 41.4 KB Views: 3
• 40.9 KB Views: 3