Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Help with sprite collisions

Years of Service
User Offline
Joined: 17th Mar 2019
Posted: 13th Apr 2019 18:45
I wanted to make a breakout game, the game is almost complete but I'm struggling to figure out how to code in side collisions for the game. I want to make it so that if the ball hits the left or right side of a block, it will change the horizontal direction (whether it goes right or left) but wont change the vertical direction (whether it goes up or down), and if the ball hits the top or bottom of the block its vertical direction will change, but its horizontal wont.
This is roughly what I have for those collisions right now, but the if statement is never true (the ball is never at the correct x position when it hits a block)

If anyone could help me out, it'd be greatly appreciated.
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 13th Apr 2019 23:04 Edited at: 13th Apr 2019 23:05
Basically, you need to check 4 events ( above, below, left and right )
Pseudocode ( after collision has taken place ):


Coders don't die, they just gosub without return
DBPro Master
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 1st May 2019 06:53
Psy's method works, until the ball starts travelling at faster speeds. Corners could also be an issue. Awhile back, I came up with a swept line intersection method that addresses those issues and wrote a tutorial.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Login to post a reply

Server time is: 2022-12-08 16:24:05
Your offset time is: 2022-12-08 16:24:05