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 / 3D Collision Detection

Author
Message
Olde Worlde Illusions
3
Years of Service
User Offline
Joined: 10th Oct 2021
Location:
Posted: 12th Jan 2022 06:18
Help,

I am using spheres for the object and am wondering how I would do collision detection? I already did
but I don't see any commands in the 3D section of the documentation for actually checking it. A little help please?
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 12th Jan 2022 08:12
That function enables the objects ability to be hit by ray (RayCasting) look at ObjectSphereCast
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 12th Jan 2022 08:42 Edited at: 12th Jan 2022 08:54
Hi OWl. Take a look here
https://forum.thegamecreators.com/thread/228144
I'm not a grumpy grandpa
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 12th Jan 2022 09:38
I all you need is to know whether two spheres are overlapping then the simplest solution is a basic distance check - if the distance between the centre points is less the the combined radii of the spheres then they must be overlapping. If it's greater then they cannot possibly be overlapping.


With the above function you pass the object ID's of the two spheres you want to check for collision. If they collide, the function returns 1. If the don't collide it will return 0.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
jd_zoo
6
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 13th Jan 2022 01:01 Edited at: 13th Jan 2022 01:04
If you are using the physics engine, i.e. your spheres are dynamic objects, the collision detection has already been checked for you.

GetObject3DPhysicsFirstContact(object1_ID) will return 1 if collision occurred in the last step. Use GetObject3DPhysicsContactObjectB() to get the object ID of what object1_ID hit. Iterate through the list of hit objects with GetObject3DPhysicsNextContact().

Edit - note there is a separate help section for 3D physics https://www.appgamekit.com/documentation/Reference/3DPhysics.htm
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 13th Jan 2022 03:46
similar to box2d, there are advantages to using bullet (3d) physics for less than a full-blown physics world which is why i nudged toward the "light" bullet example.

but, since you haven't expounded on how many objects need to be tested each frame, it's hard (for me) to offer more.
Olde Worlde Illusions
3
Years of Service
User Offline
Joined: 10th Oct 2021
Location:
Posted: 15th Jan 2022 03:15
This only works if I comment out 2 lines, so only 1 object is deleted.



So, for example:



-or-



Works but, having both active only makes 1 work. Any ideas?
jd_zoo
6
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 15th Jan 2022 14:34
Wild guess with quick look but should you be stepping backwards in your bullet loop?

Olde Worlde Illusions
3
Years of Service
User Offline
Joined: 10th Oct 2021
Location:
Posted: 15th Jan 2022 21:03 Edited at: 15th Jan 2022 23:21
Quote: "Wild guess with quick look but should you be stepping backwards in your bullet loop?

"


Nope that didn't work, here is the source code.

Attachments

Login to view attachments
Olde Worlde Illusions
3
Years of Service
User Offline
Joined: 10th Oct 2021
Location:
Posted: 18th Jan 2022 00:22
Changed it to:



Still no dice. Maybe there is a bug in the compiler itself?
jd_zoo
6
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 18th Jan 2022 01:07 Edited at: 18th Jan 2022 01:14
Are there multiple minions per bullet or vice versa? Maybe use a flag to 'exit' the minion counter loop? This wouldn't be a compiler error, I'd take another look at your method to see if you should have nested loops like this.

Have minions in your first loop. Then go through all the bullets, each bullet that hits a minion gets deleted and add a flag to the minion that it's been hit. Once the bullet loop is done delete the minion and carry on with the minion loop.

Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 18th Jan 2022 01:19 Edited at: 18th Jan 2022 01:33
i've skimmed your code and, personally, i think you're overdoing it with "collision".

in your PvZ-type, the bullets and enemies stay in the same row so, there's no need for Z axis. they also stay at the same height, so nix Y. all you need to do is compare X components of bullets in a given row vs enemies in the same row to determine "hit".

in the end, i'd compare X of all bullets in a given row vs enemies in the same row, at most.

now, with your nested loops, it appears you're deleting objects in 1 loop that may be part of the other. removing them as you're doing is going to break 1 loop or the other (if i'm seeing things right), so don't. i see JD has posted as i'm writing this and yes, don't nest the loops.

in the template that i posted, i DoEnemies() then later DoTowers(). DoTowers has immediate hit checks vs an actual "moving" bullet.

i don't know exactly how yours works but DoEnemies() then DoBullets() (with DoTowers() in there somewhere?).
Olde Worlde Illusions
3
Years of Service
User Offline
Joined: 10th Oct 2021
Location:
Posted: 22nd Jan 2022 14:44 Edited at: 22nd Jan 2022 14:45
I fixed the overly complicated collision checks and double loop issue yet, the problem persists. Also, now all the minions are destroyed instead of just the one with the collision. I think this is a timing issue cause if the defense is put in the back both all the bullets and minions are destroyed. If you put the defense in the front only all the minions are destroyed.

Attachments

Login to view attachments
Olde Worlde Illusions
3
Years of Service
User Offline
Joined: 10th Oct 2021
Location:
Posted: 23rd Jan 2022 04:17 Edited at: 23rd Jan 2022 05:24
Tried the code above to no success. Tried altering it so all objects were deleted after a hit flag was set:


Still no success

UPDATE 1: Changed it so object cleanup happens in another function:

System.agc

new


collision.agc

updated
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 23rd Jan 2022 17:10
Quote: "updated"

does that mean yout have it working correctly?
Olde Worlde Illusions
3
Years of Service
User Offline
Joined: 10th Oct 2021
Location:
Posted: 24th Jan 2022 00:04 Edited at: 24th Jan 2022 00:11
Quote: "Quote: "updated""


Quote: "does that mean yout have it working correctly?"


Nope

Attachments

Login to view attachments
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 24th Jan 2022 04:03 Edited at: 24th Jan 2022 04:38
using the method that i suggested before:



If you make the Towers Kinematic Bodies, you can use a similar "collision" routine for Enemy vs Towers (in DoEnemies()). Ie, that part...

...using the almighty GetObjects3DPhysicsContactPositionVector().

otherwise, sorry i didn't try your method. once i find something that works, i tend to stick with it

meanwhile, that would be considered "brute force" in checking each shot vs all enemies (until it hits one). the whole thing can be simplified setting linear velocities for enemies and shots (once) vs MoveObjectLocalX() each frame and simply checking for Contact(s).

alas, i wanted this to remain similar to what i think you were doing. lucky for us, Brute Force works fine for smaller stuff like this

Attachments

Login to view attachments
Olde Worlde Illusions
3
Years of Service
User Offline
Joined: 10th Oct 2021
Location:
Posted: 25th Jan 2022 00:12
I altered my code to use the almighty GetObjects3DPhysicsContactPositionVector() function my adding the required calls to Create3DPhysicsWorld(), Create3DPhysicsKinematicBody(object), SetObjectShapeSphere(), SetObjectShapeBox()
and using the above function for the actual collision, and it still isn't working.

Attachments

Login to view attachments
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 25th Jan 2022 01:40 Edited at: 25th Jan 2022 01:51
you need to add Step3DPhysicsWorld() just before Sync() just like i showed you in the last code.

i made a couple of other changes to the code before i realized that you'd missed that.

this, for one:
i also made it use WASD vs the Vstick.

i think i //'d any other changes...


Attachments

Login to view attachments
jd_zoo
6
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 26th Jan 2022 00:24
Really liking these gif demos VN, are you doing that in one easy step or do you have to screen record and then convert to gif?
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 26th Jan 2022 01:59 Edited at: 26th Jan 2022 02:03
that's gifcam: https://forum.thegamecreators.com/thread/227581

fairly simple/basic records and lightweight which is what i was after. it sits in my toolbar now.

screenshots are so '00's, i figure

Login to post a reply

Server time is: 2024-11-23 08:04:11
Your offset time is: 2024-11-23 08:04:11