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.