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 / [SOLVED] I need a rectangles overlap function that doesn't fail a collision when the corners of each recangle collide..

Author
Message
Amon
5
Years of Service
User Offline
Joined: 30th May 2014
Location: Shropshire, United Kingdom
Posted: 16th Jan 2020 20:13
Can any math guru help me out with this?
Win 10 Pro - AMD RYZEN 7 3800X Octacore - 16GB DDR4 - RTX 2080TI 11GB

The author of this post has marked a post as an answer.

Go to answer

blink0k
AGK Developer
7
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 16th Jan 2020 21:24
Maybe GetSpriteCollision()
Read the description of the command to see any caveats
Amon
5
Years of Service
User Offline
Joined: 30th May 2014
Location: Shropshire, United Kingdom
Posted: 17th Jan 2020 00:08
No, because sometimes I need to add values to the collision rectangle during runtime for what I want to work, to work. For instance, using a custom rectsoverlap means I can check the players xposition and yposition and for example have yposition + 1etc. I don't know how to do that with GetSpriteCollision which relies on sprite ID's and the shape being setup before hand.
Win 10 Pro - AMD RYZEN 7 3800X Octacore - 16GB DDR4 - RTX 2080TI 11GB
blink0k
AGK Developer
7
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 17th Jan 2020 00:22 Edited at: 17th Jan 2020 00:26
If i understand you correctly you could;

1. Save sprite position
2. Move the sprite
3. Check collision
4. If the position is incorrect, move it back

Is that what you're talking about?

Here is an AABB collision tute (Very simple) if that is what you want
Amon
5
Years of Service
User Offline
Joined: 30th May 2014
Location: Shropshire, United Kingdom
Posted: 17th Jan 2020 01:58
An AABB collision check still fails when the corners of rect1 collide with the corners of rect2.
Win 10 Pro - AMD RYZEN 7 3800X Octacore - 16GB DDR4 - RTX 2080TI 11GB
blink0k
AGK Developer
7
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 17th Jan 2020 02:46
I'm not sure i understand what he issue is. maybe an image?
chafari
Valued Member
13
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 17th Jan 2020 13:47
@Amon. Could you show us part or your code or give us more information of what you really need ? . As blink0k suggests , you coud use AABB collision without any problems in the corners .
I'm not a grumpy grandpa
Amon
5
Years of Service
User Offline
Joined: 30th May 2014
Location: Shropshire, United Kingdom
Posted: 17th Jan 2020 17:56
You guys are correct. It works perfectly. The issue was caused when multiplying my player speed by the deltatimer.

This is my RectsOverlap function. I'm suspecting it's because the function parameters are all int based. When I'm back home I'll test it further.

Win 10 Pro - AMD RYZEN 7 3800X Octacore - 16GB DDR4 - RTX 2080TI 11GB
chafari
Valued Member
13
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 17th Jan 2020 19:57 Edited at: 17th Jan 2020 20:02
I'm glad you solved . Here's an example of AABB collision .

Cheers.
https://forum.thegamecreators.com/thread/223557?page=4#

I'm not a grumpy grandpa
Scraggle
Moderator
16
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 18th Jan 2020 08:09 Edited at: 18th Jan 2020 08:10
This post has been marked by the post author as the answer.
Hi Amon,

You will presumably be calling this function every frame and probably several times every frame, so there is something you can do to speed it up.
At the moment your code performs checks for all four sides of the rectangle every time it is called but if the first check proves there is no collision then there is no point carrying out the other three.
The following code could potentially speed up your checks by 4x

Phaelax
DBPro Master
16
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 19th Feb 2020 04:10
I would change the function to use >= (greater than or equal to) to account for edge lines overlapping.
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
Scraggle
Moderator
16
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Phaelax
DBPro Master
16
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 28th Feb 2020 03:26
Oh lol i read it wrong.
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: 2020-02-29 06:06:28
Your offset time is: 2020-02-29 06:06:28