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.

AppGameKit Classic Chat / [SOLVED] AABB Collision problem

Author
Message
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 29th Jan 2019 22:16
Hi there. I've been fiddling around with Aabb collision system . I got the code working but I can't figure out why sliding collision works like a charm in z axis but get stuck in x axis . I think it must be something with te IF IF IF only the first condition works but no the rest....if I move (if x lines) to the top then x axis works perfect but z axis crash ..any idea

Here's what I have so far .

I'm not a grumpy grandpa

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

Go to answer

puzzler2018
User Banned
Posted: 29th Jan 2019 22:22
Nice... AABB vortex (cube) collisioning.- axis aligned bounding box

Awesome

Ill review code and help if i can

chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 29th Jan 2019 22:25
Ok mate ....take your time !
I'm not a grumpy grandpa
puzzler2018
User Banned
Posted: 29th Jan 2019 22:29
Your trying a little vortex world stuff arent you - great stuff

We are all remembered at least (Minecraft uses AABB)....lots must be too shy to comment.. Not to worry

Moving on..

Catch up soon with your inspriration idea of AABB
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 29th Jan 2019 22:56
Why do you need to include the position of the object in your calculations? Min/max should return the bounds
puzzler2018
User Banned
Posted: 29th Jan 2019 22:57
Object bounds correct
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 29th Jan 2019 23:00
From a 2d Tutorial


So for 3D should be
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 29th Jan 2019 23:14 Edited at: 29th Jan 2019 23:16
@blink0k Does GetObjectMeshSizeMaxZ /X /y give us the exactly coords. ??


Edit ...I will test it again Thanks.
I'm not a grumpy grandpa
puzzler2018
User Banned
Posted: 29th Jan 2019 23:16 Edited at: 29th Jan 2019 23:17
Stop guessing games, just read up on stuff instead - Knowledge!!!!

https://en.wikipedia.org/wiki/Bounding_volume

dont like wrong guessing games...
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 29th Jan 2019 23:20
@puzzler I Know what you mean....I just thought it was an easy task ...I will keep trying...thanks for the link
I'm not a grumpy grandpa
puzzler2018
User Banned
Posted: 29th Jan 2019 23:21
I keep trying too with AABB - still going to review your code
puzzler2018
User Banned
Posted: 29th Jan 2019 23:23 Edited at: 29th Jan 2019 23:25
Thats probably why no one answers - cause no one knows or they are just not procrastinating at this present time lol too busy with their love lives - headache lol JEFFFFFFREEEEEEEE TEA TIME - YES MAAAAAM
puzzler2018
User Banned
Posted: 29th Jan 2019 23:31
ill have think x
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 29th Jan 2019 23:35 Edited at: 29th Jan 2019 23:37
Quote: "Why do you need to include the position of the object in your calculations? Min/max should return the bounds"



Just tried to do the calculation without the object coords x/z and it get stuck .... I know that min /max give us object bounds, but we need to know aswell the real position x/z of every other box
I'm not a grumpy grandpa
puzzler2018
User Banned
Posted: 29th Jan 2019 23:40 Edited at: 29th Jan 2019 23:41
You example shows a 2D boxes which all collide perfectly in 2D

What is wrong or what would you like to do differently
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 29th Jan 2019 23:43 Edited at: 29th Jan 2019 23:46
Well it works ...of course but it doesn's slide ...

Edited.
This piece of code in Java, shows that they take into acount the player.x

Quote: "if(player1.x < player2.x + player2.width &&
player1.x + player1.width > player2.x &&
player1.y < player2.y + player2.height &&
player1.y + player1.height > player2.y)
{
System.out.println("Collision Detected");
}"



2 Edit.

Any way ...thanks for testing....it was just not to get bored here
I'm not a grumpy grandpa
puzzler2018
User Banned
Posted: 29th Jan 2019 23:47
Dont understand - its doing what you programmed - do you want a print "Collision Detected" message or something or convert it 3D

I works, So confused right now,

What you trying to acheive
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 29th Jan 2019 23:50 Edited at: 29th Jan 2019 23:56
1. I was wrong. The Min/Max values are local NOT world

2. They also don't take into account the rotation of the object. If however you use FixObjectPivot(), the co-ordinates will accommodate the rotation

chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 29th Jan 2019 23:55 Edited at: 29th Jan 2019 23:58
Quote: " They also don't take into account the rotation of the object. If however you use FixObjectPivot(), the co-ordinates will accommodate the rotation"


Exactly ..!! we don't need here to fix object pivot as we just check for collision in not rotated boxes...this is Ok for a dungeon system...

What I can't understand, is why when I move x lines above z lines ( I mean if z if x ) if I put x first...then it slide ok in x but wrong in z


Edited.
@blink0k hei this code is nice....I will study later. thanks
I'm not a grumpy grandpa
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 30th Jan 2019 03:46 Edited at: 30th Jan 2019 04:07
As your object rotates the values will need to be adjusted. At some point minimum x becomes minimum z, max z or max x and vice versa. As blink0k pointed out, these are based off the model space not world space.

I've attached what I use for angles 0, 90, 180 and 270. It will at least give you a start. I am sure there is a math formula... I didn't think about it at the time I created this.



If you're building a random dungeon system the direction matters.



So if you are interested - I included how I break down angles and get a directional movement. With minor adjustments you should be able to use this to get the exact size based off any rotation.
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 30th Jan 2019 12:27
@Golelorn thanks for your feedback. My object doesn't rotate ....it just move in space. The objet that we see rotating is just a helper to see the direccion against the object moves.

The code works ok... it does detect correctly when there is a collision but somehow I'm not happy with the last result as sliding collision needs some other algorithm. Thanks any way .
I'm not a grumpy grandpa
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 30th Jan 2019 14:16 Edited at: 30th Jan 2019 14:17
Quote: "What I can't understand, is why when I move x lines above z lines ( I mean if z if x ) if I put x first...then it slide ok in x but wrong in z "




Your original code had issues as it changes the z# value back to its old value then uses it to check the lines below but as its been changed then no collision will be detected. If ANY collision occurs both z# and x# need to be set to their old values and no need to do any further checks.

Sliding collision is slightly harder and involves detecting the first collision point then moving only in X or Z after that.
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 30th Jan 2019 14:43
@Bengismos Hi mate.
Quote: "
Bengismo wrote. Your original code had issues as it changes the z# value back to its old value
"


Correct about z# change value back ...thats the way z# slide, but once it detect collision . I add some lines to the same code to show that collision really happens ...What I'm trying to do here is to get Sliding Collision with AABB system .



I'm not a grumpy grandpa
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 30th Jan 2019 15:59
To be honest im not sure what your trying to do but if its just to slide on any edge then this works and is simpler too

chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 30th Jan 2019 17:25 Edited at: 30th Jan 2019 17:28
This post has been marked by the post author as the answer.
Wow Bengismo !! you did it !! .... changing just two stupid lines awesome you are an axe !! Thanks so much ...that was somehow driving crazy ...I always thought it was an easy task .



Edit.
Here's is an example of what I'm trying to do...just a AABB sliding collision for my retro Dungeon to hell.


I'm not a grumpy grandpa
puzzler2018
User Banned
Posted: 30th Jan 2019 17:59
Work well and pretty cool here too, well done to all and Bengismo for finding the solution. Awesome

Login to post a reply

Server time is: 2024-11-05 18:42:34
Your offset time is: 2024-11-05 18:42:34