how to get the bonename from c_trace ?

Posted By: Anewbie

how to get the bonename from c_trace ? - 10/27/18 14:55

I am trying to get the name of the limbs that are shot by the player in my game. I tried this by checking the old threads of this forum :

draw_text ("active", 10,10, vector(255,0,0));
var sight = 300;
VECTOR tpos;
STRING* bonename="empty";
vec_for_angle (tpos, vector (my.pan, my.tilt, my.roll));
vec_scale (tpos, sight);
vec_add (tpos, vector (my.x, my.y, my.z));
trace_mode = IGNORE_ME | IGNORE_PASSABLE | USE_BOX | SCAN_TEXTURE | IGNORE_SPRITES;
c_ignore (1, 0);
c_trace (vector (my.x, my.y, my.z), tpos, trace_mode);
draw_point3d (target.x,vector(50,50,255),100,3);
if(you && hit){

ent_bonename (you, bonename, hit.vertex);
draw_text (bonename, 10, 20, vector (255,0,0));

}


However it always shows the same bone name which is the left foot. I am using a non animated t-posing model for testing. I also would like to know how to check all the names of the bones of a model in MED.
Thanks!
Posted By: 3run

Re: how to get the bonename from c_trace ? - 10/27/18 15:25

Hi there!

a quote from the manual:
Quote:
For detecting which limb of an actor entity was hit, use the vertex number from the hit struct and retrieve the bone name with the ent_bonename function.

Take a look here:
c_trace
ent_bonename

Edit: gonna make an example, please wait


Edit2: please, take a look at this example (used guard model from my contribution):
Code:
#include <acknex.h>
#include <default.c>

#define PRAGMA_POINTER

void main(){
	
	warn_level = 6;
	fps_max = 60;
	
	level_load("");
	
	vec_set(&camera->x, vector(152, 0, 43));
	vec_set(&camera->pan, vector(180, -15, 0));
	
	def_move();
	
	ENTITY *guard_ent = ent_create("guard.mdl", nullvector, NULL);
	set(guard_ent, POLYGON);
	
	while(guard_ent){
		
		VECTOR temp;
		vec_set(&temp, vector(1024, 0, 0));
		vec_rotate(&temp, &camera->pan);
		vec_add(&temp, &camera->x);
		
		draw_point3d(&temp, COLOR_RED, 100, 4);
		
		c_trace(&camera->x, &temp, IGNORE_PASSABLE | SCAN_TEXTURE);
		
		if(trace_hit){
			
			draw_point3d(&hit->x, COLOR_RED, 100, 4);
			
			if(you){
				
				STRING *bone_name_str = "";
				ent_bonename(you, bone_name_str, hit->vertex);
				draw_text(bone_name_str, 10, 40, COLOR_WHITE);
				DEBUG_VAR(hit->vertex, 10);
				
			}
			
		}
		
		wait(1);
		
	}
	
}

It will display the bone, closest to the 'hit.x' position.


Edit3: if you want to check, which limb was hit (f.e. wanted to create hitboxes or such, to detect headshots etc), I would suggest you to use Superku's solution. You can find it in AUM 103, here. It's going to be faster.

Greets!
Posted By: Anewbie

Re: how to get the bonename from c_trace ? - 10/27/18 15:46

Originally Posted By: 3run
Hi there!

a quote from the manual:
Quote:
For detecting which limb of an actor entity was hit, use the vertex number from the hit struct and retrieve the bone name with the ent_bonename function.

Take a look here:
c_trace
ent_bonename

Edit: gonna make an example, please wait


Edit2: please, take a look at this example (used guard model from my contribution):
Code:
#include <acknex.h>
#include <default.c>

#define PRAGMA_POINTER

void main(){
	
	warn_level = 6;
	fps_max = 60;
	
	level_load("");
	
	vec_set(&camera->x, vector(152, 0, 43));
	vec_set(&camera->pan, vector(180, -15, 0));
	
	def_move();
	
	ENTITY *guard_ent = ent_create("guard.mdl", nullvector, NULL);
	set(guard_ent, POLYGON);
	
	while(guard_ent){
		
		VECTOR temp;
		vec_set(&temp, vector(1024, 0, 0));
		vec_rotate(&temp, &camera->pan);
		vec_add(&temp, &camera->x);
		
		draw_point3d(&temp, COLOR_RED, 100, 4);
		
		c_trace(&camera->x, &temp, IGNORE_PASSABLE | SCAN_TEXTURE);
		
		if(trace_hit){
			
			draw_point3d(&hit->x, COLOR_RED, 100, 4);
			
			if(you){
				
				STRING *bone_name_str = "";
				ent_bonename(you, bone_name_str, hit->vertex);
				draw_text(bone_name_str, 10, 40, COLOR_WHITE);
				DEBUG_VAR(hit->vertex, 10);
				
			}
			
		}
		
		wait(1);
		
	}
	
}

It will display the bone, closest to the 'hit.x' position.


Edit3: if you want to check, which limb was hit (f.e. wanted to create hitboxes or such, to detect headshots etc), I would suggest you to use Superku's solution. You can find it in AUM 103, here. It's going to be faster.

Greets!


Thanks a lot ! Turns out that i forgot to set the POLYGON flag. That is why it was always showing the same bone.
Posted By: 3run

Re: how to get the bonename from c_trace ? - 10/27/18 16:00

Glad to be helpful! laugh
Posted By: Anewbie

Re: how to get the bonename from c_trace ? - 10/28/18 10:42

Hi again. So today I animated the entities and the animation seems to be working well. However it seems like the bones stay in the same place during the animation. For example when the target is running and I c_trace, it shows that the bones are still in the same place as if the target was still in T pose. So in order to hit the head, hand or something like that I have to aim for an invisible T - posing target rather than the animated one.
Any solutions for this ?
Posted By: txesmi

Re: how to get the bonename from c_trace ? - 10/28/18 14:44

Hi,
http://www.conitec.net/beta/ac_updatehull.htm

Salud!
Posted By: Anewbie

Re: how to get the bonename from c_trace ? - 10/28/18 15:25

Yes, it works ! Thank you so much .
Posted By: txesmi

Re: how to get the bonename from c_trace ? - 10/28/18 19:36

Glad of been helpful
© 2024 lite-C Forums