Best collision routine for bullet shots Author Message
T3rr4Byt3
Member

10-13-2012 07:49 PM
Rubeus
Member

 Post: #2 RE: Best collision routine for bullet shots Calculate the bullet collisions as rays or segments, and use simple collision volumes whenever possible. I like to have 2 checks: 1) is the projectile even within X^2 distance of the object I am checking? I do this because distance squared is a quick, cheap calculation. I use a large area and a simple check to see if it's even worth bothering with a real collision detection. Why check collisions with everything when you can so cheaply narrow the list down to objects withing [large enough area that low framerates won't allow the object to move out of the bounds]? 2) has the bullet intersected my collision volume? I will test a line segment(LastPos, CurrentPos) against a simple, invisible shape(s) that is close form to my visible object and occupying the same space. No sense checking 10824 polygons when you can check only 30 for the same result. The physics system will probably have the same capabilities as what I just mentioned, so you most likely will not have to code it all yourself.
10-13-2012 08:34 PM
T3rr4Byt3
Member

 Post: #3 RE: Best collision routine for bullet shots Hi Rubeus, thank you for your reply. I must say that I didnt understand you - or you understand me wrong. I want to let the bullets fly over some time ( lets say, 3 secs for reaching the max distance - after traveling this distance the bullet will be deleted ) The bullets moves very fast - but after this time without hitting somewhat, the bullet get deleted. If any player gets hit (randomly) by the bullet in this time, he will lose hp - ( depending on what part of the body he was hit ). I dont want to check against every mesh / piece / capsule / sphere / box while the bullet is flying, this is done automatically by PhysX - ( even the AABBs from meshs ). -> My statement gives me a new way of thinking about the ragdoll of players. I will call ragdollblend() only when the bullet hits the player capsule - ( actor.group == AG_CONTROLLER ) - for some time. ( I dont know if there is a function which tests if an random actor is inside the capusle - ( only possible for trigger shapes ? ) ) - When this works, I will save some cpu time because ragdoll isnt enabled the whole time, only if the bullet is "inside" the capsule from player. Then, the bullet hits a capsule / sphere from the skeleton, and I will cast immediately a ray to get the faces of that physic mesh. Hm. That wont work because I need the faces of the real mesh - .... --> Else the bullet doesnt hit any shape of the player, I will get the false - bool from the "isInside" function. After receiving it, I disable the ragdollBlend(). --> [Additionally I know PhysX before I switched to EE, so Im working with the Physics.reportTrigger(..) function - but I dont see a way to get information about if the trigger is entered - inside - or leaving the shape. This is native possible in the PhysX SDK.] --> This new way of thinking gives me a problem to get the faces of the real mesh - maybe there is a function which casts a ray to a real mesh and gets his faces - where I can put a bullethole on the normal. I dont know if there is a function ( isInside, raytoMesh ..? ) in EE, but I guess so. So this is the old way to get the collision faces / the collision of the bullet. ( When the attachment works, you can see here a picture )     You see that the bullet have an box physic mesh, and I will cast a ray at the peek of that bullet. ( Very bad - because I have to cast it every time ) So I used another technique to get the ray and the collision. ( When the attachment works, you can see here a picture )     You see that the physic mesh is larger - and I will cast a ray only when the bullet gets hitted the physic mesh ( first the player capsule, then the sekeleton capsuls / spheres ) - to receive faces. [ I know, I need to get the real faces of the mesh ] So ... maybe you can understand me better with this explanataion. Do you have any ideas? Regards.
10-14-2012 10:03 AM
PsychoBoy
Member

 Post: #4 RE: Best collision routine for bullet shots How about doing first raytest with AG_CONTROLLER only and do another raytest on position of first raytest and target's actor group. Somethings like this: Code: ```PhysHit phys1; if(Physics.ray(start, move, &phys1, IndexToFlag(AG_CONTROLLER))) {     //now we're doing test inside ag_controller starting from controller pos     PhysHit phys2;     if(Physics.ray(phys1.pos, move, &phys2, IndexToFlag(AG_PLAYER)))     {         if(Player *target = CAST(phys2.obj, Player))         {             Vec closest_bone=Vec(1000);             SkelBone desired_bone;                          Skeleton *skel = target->cskel->skeleton();             FREPA(skel->bones)             {                 if(Dist(phys2.obj, skel->bones[i].center()) < Dist(closest_bone, skel->bones[i].center()))                 {                     closest_bone = skel->bones[i].center();                     desired_bone = skel->getBone(skel->bones[i].name);                 }             }         }     } }``` Not sure if I understood correctly what do you want to achieve, probably not xD
10-14-2012 05:09 PM
T3rr4Byt3
Member

 Post: #5 RE: Best collision routine for bullet shots Hi, thank you for your relpy, but that didnt solve the problem. I used my way (explained above) to solve it, it works now - where the ray is casted when the trigger shape get a hit event. But thank you again. Regards. (This post was last modified: 10-17-2012 06:08 PM by T3rr4Byt3.)
10-17-2012 06:05 PM
 « Next Oldest | Next Newest »