leopardpm wrote:in regards to your questions regarding BasicCoders code... what it does is iterate through all 4 corners of one object, comparing each corner to see if it is 'inside' the rectangle of the other object... it does this by seeing if:
Checking Collision for OBJ-A against OBJ-#
is OBJ-A corner #1 x-value between the top two corners of object OBJ-#?
if so, then is OBJ-A corner #1 y-value also between the top and bottom of object OBJ-#?
if so, then corner #1 of OBJ-A is inside of the rectangle which defines OBJ-#
Now calculate the slope from the x & y position values of both objects to determine which direction
Oh I get this solution now :D!
So our character is found within the entity.
We require an angle. That angle will tell us how our character got into the entity.
To define our angle, we require two line segments, which are defined by:
Line segment 1: from the origin (ul corner) of the collision box to character's position in entity,
Line segment 2: to define our second line segment, we require the previous position of our character (the one where it was last seen outside of entity). The line segment is defined from this point to the current point of our character.
Let us call the origin of the collision box A, the previous character position point B, and the current character position point O.
The angle AÔB will define exactly where he came from!
I have now a few queries:
1. There will be four angles where our character will have hit exactly a corner: 0°, which is the UL corner. It is finding the other three which might be an issue, as they will change depending on the size of the entity's collision box. They are important as their range defines the direction of collision, right? EDIT: figured it: just calculate them using each corner as the second line segment from point O.
2. Erm, how to find the value of angle AÔB at all? xD! Some weird black magic or other. I'll also try searching online. EDIT: watching this video from Khan Academy. Hopefully this helps. Feel free to help me on this topic though.