About Store Forum Documentation Contact
Donations:
416$/mo



Post Reply 
Bullets Collision
Author Message
Seba Offline
Member

Post: #1
Bullets Collision
In BM we have bullets collision detect and it works fine. But how to add markers in this collision detect?? In demo Small OverLays we use
Quote:
Physics.ray(pos,dir*ViewportActive.range,&phys_hit)
In BM:
Quote:Physics.cuts(Capsule(R,pos_old,pos_new),bhd);

When i changed this code from BM on that from tutorial when i was close to the wall bullets dont hit. Can i use something to have one collision detect or need make second one, or maybe i can join them?
11-25-2009 06:34 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Bullets Collision
in markers demo ray is used because we assume that shot travels at ininfinite speed, so the collision occurs in the same frame when the shot occured.
and ray assumess that collision detection is on 'point' (object of radius=0)

in BM demo, the speed is not infinite, and the radius is not zero.
11-25-2009 08:36 PM
Find all posts by this user Quote this message in a reply
Seba Offline
Member

Post: #3
RE: Bullets Collision
Ok thanks for reply.
I have another question can i detect collision between Mesh part and bullet or get what mesh part bullet hit?
11-25-2009 11:55 PM
Find all posts by this user Quote this message in a reply
Seba Offline
Member

Post: #4
RE: Bullets Collision
I try to detect which mesh part i hit i use that code but it works fine only in some shots and object:
Code:
REP(stat->mesh->parts())
                  {
                      Box mesh_box;
                      Box test_box;
                      test_box.set(pos_old,pos_new);
                      stat->mesh->part(i).getBox(mesh_box);
                      Vec udezenie(0,0,0);
                      if(Sweep(pos_old,T.dir,stat->mesh->part(i).base/*mesh_box*/,NULL,NULL,&udezenie))
                      //if(Cuts(test_box,mesh_box))
                      {
                          AddMessage(S+"Zderzenie z meshpart: "+stat->mesh->part(i).name);
                      }
                      AddMessage(S+"Udezenie: "+udezenie);
                  }
I changed Cuts and Sweep with different values.
11-28-2009 08:07 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #5
RE: Bullets Collision
please don't use MeshPart::getBox in realtime because it's slow

do you want character bone collision?
then you should use skeleton bones as shapes (capsules), or use temp ragdolls like in physical cloth tutorial
11-28-2009 08:15 PM
Find all posts by this user Quote this message in a reply
Seba Offline
Member

Post: #6
RE: Bullets Collision
I shoot first i get collision like in BM ten use physics all code look like that:
Code:
PhysHit phys_hit;
      if(Physics.ray(pos_old/*pos_start*/,dir*ViewportActive.range,&phys_hit))
      {
          if(phys_hit.obj) // if the actor comes from an object
          {
              if(STATIC *stat=CAST(STATIC,phys_hit.obj)) // if the object is an item
              {
                  REP(stat->mesh->parts())
                  {
                      Box mesh_box;
                      Box test_box;
                      test_box.set(pos_old,pos_new);
                      stat->mesh->part(i).getBox(mesh_box);
                      Vec udezenie(0,0,0);
                      if(Sweep(pos_old,T.dir,stat->mesh->part(i).base/*mesh_box*/,NULL,NULL,&udezenie))
                      //if(Cuts(test_box,mesh_box))
                      {
                          AddMessage(S+"Zderzenie z meshpart: "+stat->mesh->part(i).name);
                      }
                      AddMessage(S+"Udezenie: "+udezenie);
                  }
                  stat->addBulletHole(phys_hit.plane.p, phys_hit.plane.n, dir); // call item method to add a bullet hole
                  stat->particlecreate(phys_hit.plane.p,T.dir*(-1,-1,-1));
              }
              else
                  if(ITEM *item=CAST(ITEM,phys_hit.obj))
                  {
                      item->actor.addImpulse(T.dir * 3.0f,phys_hit.plane.p);
                  }
          }
          else // the actor doesn't have an object set, so most probably it's a terrain actor
          {
              // add a marker to the world terrain
              Game::World.terrainAddMarker(WHITE,0,*Images("gfx/hole/bullet.gfx"),Matrix().setPosDir(phys_hit.plane.p, phys_hit.plane.n),0.1f,0.05f,0.05f);
              Image *image   =Images("particle/drop.gfx");
              Color  color   =Color(255,167,166,164); // particle[3] will be rendered in a different way (alpha blended) so make sure to set up alpha value in the color
              Int    elms    =500;
              Flt    radius  =0.3,
                  life_avg=1.5;
              b_particle.New().create(image,color,elms,radius,life_avg) // create particles
                  .source(phys_hit.plane.p);       // set generation source to a single point
              Flt i=b_particle.elms()-1;
              b_particle[i].vel_random=2.8;           // set random velocity
              b_particle[i].accel=dir*Vec(10,10,10);
              b_particle[i].reset(); // move to the left and reset every single particle
              b_particle[i].reborn=false;
              b_particle[i].life_total=2.0;
          }
      }
When i get collision and obj is Static i want to know what mesh part bullet hit.
11-28-2009 08:27 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #7
RE: Bullets Collision
this is wrong test_box.set(pos_old,pos_new); (set(min,max))
and you forget that mesh is transformed by matrix
11-28-2009 08:39 PM
Find all posts by this user Quote this message in a reply
Seba Offline
Member

Post: #8
RE: Bullets Collision
Ok but when i use Cut(test_box,mesh_box) i dont get any collision.
I only got some when i use:
Code:
if(Sweep(pos_old,T.dir*ViewportActive.range,stat->mesh->part(i).base,NULL,NULL,&udezenie))
Then when i shoot i get information that i hit some mesh part. But it dont work in every shoot and in some models dont work.
How works Sweep and Cut??
11-28-2009 09:08 PM
Find all posts by this user Quote this message in a reply
Seba Offline
Member

Post: #9
RE: Bullets Collision
We have a file hole/bullet.gfx; In this file we have a white background that we cant see in game how to do that. I have my file but i get white background. I must convert it somehow or i made my file wrong?
11-28-2009 10:46 PM
Find all posts by this user Quote this message in a reply
Seba Offline
Member

Post: #10
RE: Bullets Collision
Can someone help me with this mesh parts collision? I need it to go forward in my code. If i cant done it i must change my code.
My code for update:
http://www.wklej.org/id/219149/
11-29-2009 11:48 AM
Find all posts by this user Quote this message in a reply
Seba Offline
Member

Post: #11
RE: Bullets Collision
I change sweep like that:
Quote:if(Sweep(pos_old,T.dir*ViewportActive.range,stat->mesh->part(i).base,&stat->matrixScaled(),NULL,&udezenie,NULL))
But i only get collision i some pleaces. Can i get some help with it?
12-04-2009 10:08 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #12
RE: Bullets Collision
you shouldn't use collision detection on Mesh MeshBase because its slow

more likely add a few skeleton points to the object skeleton, when collision occurs using physics detecion, then calculate the nearest skeleton point to the bullet.
12-04-2009 10:15 PM
Find all posts by this user Quote this message in a reply
Seba Offline
Member

Post: #13
RE: Bullets Collision
So slow is the reason i got collision i some cases in other no?
So i try to change it to skeleton.
12-04-2009 10:59 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #14
RE: Bullets Collision
the Sweep function requests the inversed object matrix
12-04-2009 11:05 PM
Find all posts by this user Quote this message in a reply
Seba Offline
Member

Post: #15
RE: Bullets Collision
Thanks for help. It works now, and i can move forward with my code.
12-04-2009 11:51 PM
Find all posts by this user Quote this message in a reply
Post Reply