cTrace on specific section of model?

Posted By: Ruben

cTrace on specific section of model? - 12/25/17 04:14

I am trying to make it so that if the player hits a certain section of an NPC, like say the head, something will happen. Otherwise, nothing will happen. I know that cTrace can be used to detect whether the player hits the NPC model anywhere on its body. Is there a way to specify this for only one specific body part of the NPC, like say, the head, rather than the whole body?

For example, if I want to detect whether the player hits a sword on the model, this is what I have done so far:

Code:
action NPC_action()
{
   ...

   me = npcPerson;

   my.ENEMY_CODE = 7;

   ...

   while(1)
   {
      ...

      sword_ctrace();

      ...
  
      wait(1);
   }

   ...
}

void NPC_Create()
{
   npcPerson = ent_create("npcModel.mdl", vector(-64,146,-111),
      NPC_action );
   ...
}	

action sword_ctrace()
{
   var tip_sword;
   var hilt_sword;
	
   ...
	
   vec_for_vertex (tip_sword, sword, 54);
   vec_for_vertex (hilt_sword, sword, 50);
	
   ...
	
   if (c_trace (tip_sword, hilt_sword, IGNORE_ME | IGNORE_PASSABLE) >
       0)
   {
      ...

      if(you.ENEMY_CODE == 7) // Detects entire NPC model, but not 
                              //    specific body part like head.
      {
         NPC_health -= sword_damage * time_step;
      }
		
      ...	
}



Does anyone know how I can have the sword only detect the head of the NPC, or any other specific bodypart like the arm or leg, rather than the whole body?
Posted By: Superku

Re: cTrace on specific section of model? - 12/25/17 17:16

Try c_trace with SCAN_TEXTURE, then use hit.vertex as the vertex argument for ent_bonename.
Posted By: Ruben

Re: cTrace on specific section of model? - 12/28/17 05:02

Thank you Superku! Your advice seems to be working. When I used ent_bonename along with hit.vertex and beep(), the c_trace is beeping when the player makes contact with the vertice areas controlled by a certain bone that I specify in the code. So, this should open the door for me to fulfill specific body part functionality, such as armor resistance at different body locations. Thank you again! :-D
© 2024 lite-C Forums