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 / (Tier 1) -- how do I check if two 3D objects overlaps, without having them colliding?

Author
Message
basicFanatic
6
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 13th Aug 2017 23:33
I have made two simple objects

Create3DPhysicsWorld(1)



And then I use this code to check if they have contact:

CheckContact = 0
CheckContact = GetObject3DPhysicsFirstContact( crudePositionHackSphere )
if CheckContact > 0
SetObjectColor (crudePositionHackSphere, random(1, 255),random(1, 255),random(1, 255),255)
endif

The contact is detected. However, the objects are coliding, pushing each other apart. Is there a way to detect their contact, without it having a 3D physics reaction?


basicFanatic
6
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 20th Sep 2017 10:58
Man, this one still bugs me! It must be possible somehow, but I just can't figure it out...
Green7
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 20th Sep 2017 12:01 Edited at: 20th Sep 2017 12:02
it may be that your objects are way to small... the smallest thing the physics engine detects is 3x3 units if i remember well. better bigger than this. this however may not solve your problem. maybe you can set the physics off after the contact.
basicFanatic
6
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 20th Sep 2017 21:29
Thanks, never knew of tha t3x3 limit ... but that might be why some other collision screwed up. I tried turning physics off, and it's a clever idea and all ... only, I couldn't get it to play along. And even if I got it to work, I'm afraid that it'll come back a bite me later on. Also, I sort of feel that it's a bit much, having to rely on a crude hack (sorry) for a basic collision detection...
Green7
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 21st Sep 2017 08:27
colision detection can be achieved by raycasting. i think sphere casting would do a good job, but i do not fully understand the concept of sphere casting, as i am a visual person and do not get abstract stuff so easy. i always wanted to ask someone to draw me a sketch of how sphere casting works.
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 21st Sep 2017 20:29
SetObjectCollisionMode(boxThing,0) command is not for use with the 3D physics commands.
So using it here does nothing.

Did you look at the 3D Physics demos here.

https://forum.thegamecreators.com/thread/216683

Quote: "The contact is detected. However, the objects are coliding, pushing each other apart. Is there a way to detect their contact, without it having a 3D physics reaction?
"


Do not use 3D Physics.
The coffee is lovely dark and deep,and I have code to write before I sleep.
basicFanatic
6
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 22nd Sep 2017 09:26
Sorry, but I think I missed your point. If your advice is "Do not use 3D Physics" ... what should I use then?
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 22nd Sep 2017 14:38 Edited at: 22nd Sep 2017 14:40
Quote: "what should I use then?"

Use a distance check?

distance# = sqrt( Obj1XPosition# * Obj2XPosition# + Obj1YPosition# * Obj2YPosition# + Obj1ZPosition# * Obj2ZPosition# )

If object1 is distance# units away or less from object2 then they collide.
Click here for VR Legend of Zelda stuff
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 22nd Sep 2017 16:07
I inferred the question as more "how to detect if an object passes in front of another object"? (i.e. overlap without touching right?)

You could probably spherecast from the camera can check for multiple hits?

Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 22nd Sep 2017 22:17
Paul could add triggers to the 3D physics.
The coffee is lovely dark and deep,and I have code to write before I sleep.
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 22nd Sep 2017 23:08 Edited at: 22nd Sep 2017 23:20
CJB wrote: "You could probably spherecast from the camera can check for multiple hits?"


that could be the solution Here is a function i used for few of my old WIP games (can surely be optimized now with AGK2) for multiple object collisions (but maybe you don't need this if you only need to exit your collision's test if the first collided object is NOT the desired object... this function is useful if you need to pass through few objects before the desired object test) ... but you will have to raycast around your object (bounding box coordinates ?) or using a spherecast diameter approximatively equal to your object size ...


Multi-Objects collisions code :
--------------------------------
Join us on dedicated AppGameKit WeeKChat :
https://week.chat/room/AppGameKit
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 26th Sep 2017 09:40
I had a similar problem, all I did was convert the boundaries of the object to we screen coords then is was simple maths that did it. That's how I detect if the players 2d ship is over a 3d planet in my game.

May not be the most graceful solution, and only works well on square shapes (Collison boxes) but it depends how accurate and fast you want it.

Login to post a reply

Server time is: 2024-03-29 07:33:27
Your offset time is: 2024-03-29 07:33:27