make an arrow stick to the hit entity

Posted By: Altarius

make an arrow stick to the hit entity - 11/26/14 18:47

Hi,

Im using a model for my projectile arrow and im trying to figure out how to make it stick to the entity it hit, following his animation and movement.

I have started something using "ent_getvertex" but im kinda lost.

Anyone can give me a hint plz.

Thx.
Posted By: rayp

Re: make an arrow stick to the hit entity - 11/26/14 20:09

Hi.

Here's an example how to place a sprite that will follow another entity ( taken from: http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=414718 )
Code:
define selected skill100

void selection_sprite(){ // fex a circle sprite
	set(my,PASSABLE|TRANSLUCENT);
	my.tilt += 90;
	while(you){	
                vec_set(my.x, you.x);	
		if (you) if (!you.selected) break;
		wait(1);
	}
	wait(1);
	ptr_remove(me);
}

..
my.selected = 1;
ent_create("circle.tga", vector(my.x, my.y, my.z), selection_sprite);

..
wait(-1);
my.selected = 0;



Besides the following commands where made for that:
Code:
vec_for_vertex, vec_for_bone, vec_set

example ( taken from here http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=404673 )
Code:
VECTOR _p,_a;
vec_for_bone(_p, ThePlayer, "Righthand");
ang_for_bone(_a, ThePlayer, "Righthand");
vec_set(Axe.x, _p.x); //set the axe to the right hand
vec_set(Axe.pan, _a); //and rotate it with the animation of the bone



edit: If you want to stick a model to last hit position you could do it like this ( just wrote it, but didnt test )
Code:
.
..
...
c_trace (...);
if (you){                   // hit entity?
   you.skill1 = hit.vertex; // store vertexnr in skill1
   example_arrow (you);     // create arrow at hit pos
}
...
..
.
void example_arrow (ENTITY* _ent){
   proc_mode |= PROC_GLOBAL;
   if (!_ent) return;
   ENTITY* your_mdl = ent_create ("arrow.mdl", nullvector, NULL);
   if (!your_mdl) return; // creation error?
   set (your_mdl, PASSABLE);
   while (_ent && your_mdl){ // hit-you and arrow-mdl != NULL
      vec_for_vertex (your_mdl.x, _ent, _ent.skill1); // set pos of saved vertexnr
      wait (1);
   }
   wait (1);
   ptr_remove (your_mdl);
}


Greets
Posted By: Altarius

Re: make an arrow stick to the hit entity - 11/26/14 20:41

Nice thx a lot.

But i dont know wich part of the entity the arrow gonna hit, so i cant know wich bone this part are controled by. That's why im suposing to use ent_getvertex for find the closest vertex of the hit spot,when the arrow hit the model for
determinate where the arrow need to stick, then vec_for_vertex for followind the model animation and movement.

But maybe im wrong.

Posted By: rayp

Re: make an arrow stick to the hit entity - 11/26/14 20:59

Yes your idea is right. Please see my last edit ( just done ). Its a simple example of that. After a c_trace the closet vertex to hitposition will be saved in hit - entitys skill1. Then a function creates a arrow model ( or whatever ). This one will be placed at position taken from vertex nr saved in skill1. Hope it helps.
Posted By: Altarius

Re: make an arrow stick to the hit entity - 11/26/14 21:07

Cool! im gonna try this. Thx again .
© 2024 lite-C Forums