Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (1 invisible), 692 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
best way to attach weapons #472394
04/24/18 22:12
04/24/18 22:12
Joined: Mar 2018
Posts: 37
Blobfist Offline OP
Newbie
Blobfist  Offline OP
Newbie

Joined: Mar 2018
Posts: 37
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


Last edited by Blobfist; 04/24/18 23:46.
Re: best way to attach weapons [Re: Blobfist] #472400
04/25/18 20:34
04/25/18 20:34
Joined: Jul 2008
Posts: 2,107
Germany
rayp Offline

X
rayp  Offline

X

Joined: Jul 2008
Posts: 2,107
Germany
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

Last edited by rayp; 04/25/18 21:14.

Acknex umgibt uns...zwischen Dir, mir, dem Stein dort...
"Hey Griswold ... where u gonna put a tree that big ?"
1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected
rayp.flags |= UNTOUCHABLE;
Re: best way to attach weapons [Re: rayp] #472405
04/25/18 23:27
04/25/18 23:27
Joined: Mar 2018
Posts: 37
Blobfist Offline OP
Newbie
Blobfist  Offline OP
Newbie

Joined: Mar 2018
Posts: 37
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


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1