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.

Dark GDK / Another 2D collision problem

Author
Message
JIMAC
7
Years of Service
User Offline
Joined: 25th Nov 2011
Location: Scotland
Posted: 10th Jul 2012 18:42 Edited at: 10th Jul 2012 18:45
Hi guys you probably know me by now as the 2D pain

I just started a simple pong project, i made some sprites for wall barriers and stuck them in, now the problem is i had to rotate them to make my game board look the way i wanted it (hexagon shape) when i put in collision testing the map looks fine but there is invisible walls that cause the ball to bounce even though i'm using sprite collision, anyways heres my code has anyone else had these issues?




www.pricklyproductions.co.uk
darkvee
13
Years of Service
User Offline
Joined: 18th Nov 2005
Location:
Posted: 27th Oct 2012 23:46
If I was you I would make a simple back and forth collision from each
screen x. So it would be like a bouncing ball back and forth.

After that you make it just bounce off the screen y back forth.

darkvee
Mister Fuzzy
8
Years of Service
User Offline
Joined: 27th Feb 2011
Location: XNA
Posted: 31st Oct 2012 03:54 Edited at: 31st Oct 2012 04:09
The problem you're having here is that even when you rotate an image resource, the outer bounding box remains a rectangle: It doesn't rotate WITH the sprite. To remedy this, you need to think back to Algebra 1: Linear Functions. Because your map deals with straight lines, you need to create (invisible) lines that can be checked to see if a particular point is above, below, or on that line. You should remember that a line's function is Y = aX+B, where A is the slope and B is the vertical translation. All you need to do is align the linear functions (do the math yourself, lazybones!) with the inside of your outer walls, and use a simple check equation to see if a point is above or below that line, such as:



Hope this helps!

It's been fun: So long, TGC!
https://plus.google.com/111906249484167295353
Wizz
10
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 5th Nov 2012 22:34
In my experience, using this engines collision detection functions is a waste of your time. They never seem to work properly. Try to come up with your own way to detect collision. It shouldn't be too hard in 2D.

JIMAC
7
Years of Service
User Offline
Joined: 25th Nov 2011
Location: Scotland
Posted: 9th Jan 2013 21:05
Quote: "Algebra 1: Linear Functions. Because your map deals with straight lines, you need to create (invisible) lines that can be checked to see if a particular point is above, below, or on that line. You should remember that a line's function is Y = aX+B, where A is the slope and B is the vertical translation."


Spot on, Legend thank you!

Login to post a reply

Server time is: 2019-09-17 10:01:46
Your offset time is: 2019-09-17 10:01:46