|
best way to attach weapons
#472394
04/24/18 22:12
04/24/18 22:12
|
Joined: Mar 2018
Posts: 37
Blobfist
OP
Newbie
|
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.
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:
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
X
|
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.
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
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;
|
|
|
|