About Store Forum Documentation Contact



Post Reply 
Best collision routine for bullet shots
Author Message
T3rr4Byt3 Offline
Member

Post: #1
Best collision routine for bullet shots
Hi,


I want to shoot bullets from my weapons - and Im not sure about the best way to add collisions.

These bullets shouldn´t reach the "destination", in the same frame where I shot them, ( raycast ) they should travel to the destination point. The bullet have a light gravity so they are going to fall on the ground. My first attempt was a box physics which I designed to the bullet. I enabled the trigger-shape function so each bullet will call an trigger event when they pass throu a physic mesh. I also call every update the ragdollblend() for players / characters, so they are able to get shoted at arms, legs etc.

[EDIT] I dont want to use a "near" collision routine like in Bloody Mascare.
Because this is to inaccurate and not useful for me. ( No bullethole positions and arm / leg differences possible ! )


This already works , so that isnt my question.

My question is - is there a better way to "calculate" collisions between the bullet and the environment / players / character etc ?

Im guess that a raycast from each bullet with a very little length would be more stressful for the cpu than a triggershape which is already moving ( very fast, ccd is off ). I didnt add velocity to the bullet, Im calculation the new position with matrix*Time.d()*direction;.

So I dont know which way is better, the raycast which is very short but constantly (rayed? / calculated) or a simple trigger shape which only set his position along the matrix.

So I really want many bullets in my game at the same time ( lets say 40 enemies whos shoting with a mechgun about 10 rounds / second = 400 bullets ( box´s or raycast ) the second.

Additionally, I want to create bulletholes everywhere where bullet
hits the mesh. ( Terrain, barrels, .... humans ).
So only the raycast give me the informations about the impact place
- so I guess i have to use a hybrid version to solve it.
( Cast only a ray if trigger shape gets triggered )


I also want to create rockets, but rocket fly slower than bullets, so they should be able to get shoted. ( The trigger shape is the best way to solve it. )

I didnt find any useful information about my problem.

But I guess this is the right way to solve it.
What do you prefere?

Do you have any ideas?

Regards.
(This post was last modified: 10-13-2012 08:00 PM by T3rr4Byt3.)
10-13-2012 07:49 PM
Find all posts by this user Quote this message in a reply
Rubeus Offline
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
Find all posts by this user Quote this message in a reply
T3rr4Byt3 Offline
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
Find all posts by this user Quote this message in a reply
PsychoBoy Offline
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
Visit this user's website Find all posts by this user Quote this message in a reply
T3rr4Byt3 Offline
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
Find all posts by this user Quote this message in a reply
Post Reply