best way to attach weapons

Posted By: Blobfist

best way to attach weapons - 04/24/18 22:12

So I used vec_for_bone to attach an rifle model to my character model.
It works without any issue, however positioning of the weapon can only be achieved through manually adjusting the angle of the weapon to different animation stages (standing, walking, aiming and not aiming, etc.) is very unpractical.

Code:
action attach_weapon()
{
	proc_mode = PROC_LATE;
	//
	ENTITY* actor = you;
	//
	set(my,PASSABLE);
	//////////
	while(actor.health>0)
	{
	        // attach weapon to bone. 
		vec_for_bone (my.x,   actor, "Bip01_R_Finger0");
		ang_for_bone (my.pan, actor, "Bip01_R_Finger0");
		//////////
              /*  individual adjustments of the weapon depending on current animation set of the character in order to keep the positioning/angle correct */
		if(my.state >= 1)
		{
			if(actor.move_speed>1)
			{
				my.tilt -= 80;
				my.pan += 45;
				my.roll += 20;
			}
			else
			{
				my.tilt -= 80;
				my.pan += 0;
				my.roll += 20;
			}
		}
		else
		{
			my.tilt -= 70;
			my.pan -= 10;
			my.roll += 20;
		}
		wait(1);
	}
	wait(1);
	weapon_model();//spawn weapon
}



That is tidies and I am sure there is a smarter way to attach a weapon more reliable and with less effort.

My attempt to improve, which did not work (for some reason), was the the following:

Code:
VECTOR bonevec, bone1, bone2;
ANGLE boneang;
//////////
vec_for_bone (bone1.x,   actor, "Bip01_R_Finger0");
vec_for_bone (bone2.x,   actor, "_no_name_13");	
vec_set(bonevec,bone2.x); 
vec_sub(bonevec,bone1.x);
vec_to_angle(boneang.pan,bonevec);
ang_for_bone (boneang.pan, actor, "Bip01_R_Finger0");
/*weapon is attached to bone1, while the angle boneang is always facing bone2 from bone1*/



The idea was to the attach the weapon to a certain bone and have it face the direction of another bone which is positioned in a way that the weapon would always have the correct angle.

However, the weapon does not attach in the first place with the script above Oo

Posted By: rayp

Re: best way to attach weapons - 04/25/18 20:34

Give this a try.

This creates a entity and sticks it to a Special bone. Sry if i missunderstood your question.
Code:
void apply_sword(){
   VECTOR ang, pos;
   while (you){ // do as long player != NULL
      // move with players animation
      vec_for_bone(pos, you, "Right Hand"); // get xyz pos of hand bone
      ang_for_bone(ang, you, "Right Hand"); // get rotation of hand bone
      vec_set(my.x, pos.x); // set xyz
      vec_set(my.pan, ang); // set rotation

      // optional animation
      //my.skill1 += time_step;
      //ent_animate(me, "idle", my.skill1, ANM_CYCLE);
      wait(1);
      }
      ptr_remove(me); // no more player ? remove weapon
}
..
action myPlayer()
{
  player = me;
  // create the sword and apply to players hand
  ent_create("sword.mdl", vector(player.x, player.y, player.z), apply_sword);
}



When thinking of best way i would use one while
Code:
action myPlayer(){
   ..
   ENTITY* sword = ent_create (...)
   ..
   while (my.health > 0){ // or whatever
      ..
      if (sword){ // place code from above here vec_for_bone etc
         vec_for_bone...
         ...
         vec_set (sword.x,....);
         ..
      }
   wait (1);
   }
   ..
}


Greets
Posted By: Blobfist

Re: best way to attach weapons - 04/25/18 23:27

That does better attach the model to the bone.

What I did was rotate and position the weapon manually via MED.
Now it is perfect
© 2024 lite-C Forums