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 RayCast / SphereCast through multiple objects ?

Author
Message
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 10th Feb 2013 17:57
Actually, ObjectSphereCast() or ObjectRayCast() only return the first collision (or not collision at all).

GetObjectRayCastNumHits : "Returns the number of collisions that occurred in the last collision check. In the case of ObjectRayCast and ObjectSphereCast this will be 0 or 1."

Is it possible to have another function (or the same) which permits to return all the objects crossed by the ray ? (and use the same index system as GetObjectRayCastNumHits and GetObjectRayCastHitID )

Actually i use a workaround doing multiple collision tests on the same vertical Ray for my Speed Racer game and target it to a specific ObjectID to avoid it to return only the first collision ID. I want be able to see collisions for all object on the same vertical ray at the same time.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 10th Feb 2013 18:42
did you use the Ray intersect for shooting or why?
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 10th Feb 2013 18:51
Not for the moment. But i use it to follow the terrain and check if we are crossing checkpoints. (and it could be done at the sametime !)

For the moment i have to do a lot of calculation and split these checks to prevent the terrain following to "jump" when the checkpoint is at the same place and is returned at first collision (the only collision permitted with Raycast or spherecast).
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 10th Feb 2013 19:21
ah, i understand.

why not use the distance between to spheres for aircraft and checkpoint?
you need only 2x xyz position and radius
.--.
you see <= radius+radius inside else outside
(the only think is you can step over, but you can
add the frame speed at radius therefor.)

dx=x2-x1
dy=y2-y1
dz=z2-z1
distance=sqrt(dx*dx + dy*dy + dz*dz)

then you need only raycast aircraft-terrain for the height.
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 10th Feb 2013 20:41 Edited at: 10th Feb 2013 20:42
i don't want to loop over all the checkpoints or other objects to check the distance. Actually i do a loop over the terrain parts.

There will be more checkpoints and interactive objects than terrain parts.

Just to take into account that objects and checkpoints must not be on the same vertical ray ... lol

Check distances will be my last option if i have no other choice (but i hate doing loops lol)
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 10th Feb 2013 21:16
maybe for the terrain you can use a array(x,z) grid what have the height.
i saw you create the hi maps yourself and save the .obj file,
you can save/load a array with the height too.
it would be faster than ray tracing, you get the height very fast
direct from array.

in the 2d physics we can use a bullet mode & sensor, did the 3d have this too?
then you can use the build in collision detection for checkpoints or collecting objects.
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 10th Feb 2013 23:33
Quote: "i saw you create the hi maps yourself and save the .obj file,"


Not in this case ! for my heightmap sample yes, i can do it interpolating around vertices heights from array and exact position ... but not for my speed racer game which use precomputed obj files.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 11th Feb 2013 08:24
maybe you can make the objects you don't need for a ray cast invisible, and after you show it. i know you hate loops
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 11th Feb 2013 09:36
RayCast also take the invisible objects into account (and it's what i awant ! my CheckPoints Box are invisible !)
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 11th Feb 2013 10:39
Not sure if this was answered above without reading all of the thread but if you use raycasting you can get all of the objects the ray crosses using the index system IE.



this.mess = abs(sin(times#))
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 11th Feb 2013 12:15
baxslash example looks good.
maybe ray cast use the collision on/off flag and not visible.
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 11th Feb 2013 17:34 Edited at: 11th Feb 2013 17:36
Quote: "Not sure if this was answered above without reading all of the thread but if you use raycasting you can get all of the objects the ray crosses using the index system IE.
"


Bax :

GetObjectRayCastNumHits : "Returns the number of collisions that occurred in the last collision check. In the case of ObjectRayCast and ObjectSphereCast this will be 0 or 1."

It only returns 0 (no collision) or 1 (first collision) as said in the documentation(with 108 beta 8)

I'm using GetObjectRayCastNumHits for ObjectSphereSlide but it returns only the collisions points used to create the Sliding coordinates (iterations.. also describes in the documentation).... so i can get only the neighboring collision points and not all objects crossed by the ray.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 11th Feb 2013 17:39
Oh, that's a misunderstanding on my part then. If you are looking for a specific object you can do a raycast on just that object, but if you want all objects along a ray you may have to move each object out of the way and do another raycast until no more hits are returned, then move all the objects back into position. A pain I know but it wouldn't be too hard to create a function to do that for you.

I did this in a game I made a few years ago using Sparky's collision and DBPro. The collision system in AppGameKit is actually based on Sparky's so it should be just as quick and not impede on gameplay at all.


this.mess = abs(sin(times#))
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 11th Feb 2013 17:47 Edited at: 11th Feb 2013 17:47
Good idea Bax ! i will test your idea (hoping it's not a cpu killer ...)
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 11th Feb 2013 19:45 Edited at: 11th Feb 2013 19:50
SetObjectCollisionMode( iCube, 0 ) make the object invisible for
the ObjectRayCast

MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 11th Feb 2013 21:25
Yes i know i already use it and i will try it instead of moving objects away during scanning collisions
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 12th Feb 2013 00:55 Edited at: 12th Feb 2013 04:39
Edited : Works

however i used SphereCast with a radius instead of raycast (doesn't change anything with RAYcast when i change collision modes or when i move objects away .. Raycasting stay on the first hit !! very strange.. maybe raycast use frontbuffer instead of the backbuffer ... i dont know)...


Snippet :


Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 12th Feb 2013 08:42
your last code snippet confused me
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 12th Feb 2013 12:01
There was a bug a while back where raycasting was only reporting the first object. If you are using v1088 then it is likely the fix hasn't been released yet. I have been using raycasting successfully since Paul fixed that one bug. Using a spherecast with a small radius should be ok for now though...


this.mess = abs(sin(times#))

Login to post a reply

Server time is: 2024-11-24 07:57:54
Your offset time is: 2024-11-24 07:57:54