|
Attach Model
#211666
06/17/08 18:11
06/17/08 18:11
|
Joined: Jan 2002
Posts: 454 Germany
CD_saber
OP
Senior Member
|
OP
Senior Member
Joined: Jan 2002
Posts: 454
Germany
|
Hello,
I do not understand why the code doesn't work. I have a model (a player with a sword) and separated them as 2 models (because i wanted to assign a fx to the sword). I tried to attach the sword to the playermodel with this code:
action swordaction { my.material=glowmodel;
my.passable = ON; while(1) {
my.scale_x = player.scale_x; my.scale_y = player.scale_y; my.scale_z = player.scale_z; my.frame = player.frame; my.x = player.x; my.y = player.y; my.z = player.z; my.pan = player.pan; my.tilt = player.tilt; wait(1); } my.bright=on; // my.nofog=on; //
}
But it does not work correctly! The frames do not alway fit, and sometimes it looks like the swords position is wrong... why?
please help me, thank you
Ja, lach du nur du haariges Pelzvieh!
|
|
|
Re: Attach Model
[Re: CD_saber]
#211693
06/17/08 19:47
06/17/08 19:47
|
Joined: May 2008
Posts: 73 Richmond, VA (USA)
coma_dose
Junior Member
|
Junior Member
Joined: May 2008
Posts: 73
Richmond, VA (USA)
|
I'm not sure why, I can say that sometimes using a sort of attachment code will mess up due to the fact that there is a gap between when the player's position is updated and when the sword's position is updated. Try putting proc_late(); at the top of the sword code, this will make it so that it is updated AFTER the player instead of before. It may help, it may not, it may help only a little. Also, are you using ent_animate with anm_cycle to animate the player? Using that and then using my.frame = player.frame tends to mess up around the end of the player animation cycle because the last frame is blended to the first frame. You could either make a code that ent_animates the sword based on the player's animation speed --- ent_animate(me,"walk",player.anim_dist,anm_cycle); --- or you can use anm_add and just make sure that your animations cycle well on their own. Also, also; instead of this:
my.scale_x = player.scale_x;
my.scale_y = player.scale_y;
my.scale_z = player.scale_z;
Use this, it's faster, speed is the issue with sync:
vec_set(my.scale_x,player.scale_x);
Do the same for the other vectors; use vec_set(my.x,player.x); and vec_set(my.pan,player.pan); check out vec_set in the manual. It's most likely a problem that can be fixed using proc_late(); and vec_set.
|
|
|
Re: Attach Model
[Re: coma_dose]
#211729
06/18/08 00:15
06/18/08 00:15
|
Joined: Oct 2004
Posts: 1,655
testDummy
Serious User
|
Serious User
Joined: Oct 2004
Posts: 1,655
|
Please ignore the following:
STRING md_wp1 = "sword1.mdl";
define _eWp1, skill70;
ENTITY* e1;
STRING* sAni1;
var nAniStep = 0;
var nAniMode = 0;
var nAniPer = 0;
var n1 = 0; // temp var
function wpf_valid1() {
e1 = NULL;
if (my._eWp1 == 0) { return(0); }
e1 = ptr_for_handle(my._eWp1);
if (e1 == NULL) {
return(0);
}
return(1);
}
function wpf_align1(_bScale) {
if (e1 == NULL) { return(0); }
if (_bScale) { vec_set(e1.scale_x, my.scale_x); }
vec_set(e1.x, my.x);
vec_set(e1.pan, my.pan);
return(1);
}
function wpf_new1(_s, _bAlign, _bScale) {
if (my._eWp1 != 0) { return(0); }
if (_s == 0) { return(0); }
e1 = ent_create(_s, my.x, NULL);
if (e1 == NULL) { return(0); }
my._eWp1 = handle(e1);
e1.passable = ON;
if (_bAlign) {
wpf_align1(_bScale);
}
return(1);
}
function actorf_ani1(_s, _nStep, &_nPer, _mode) {
_nPer[0] += _nStep * time_step;
//_nPer[0] %= 100;
ent_animate(me, _s, _nStep, _nPer[0], _mode);
if (wpf_valid1() == 0) { return(1); }
wpf_align1(0);
ent_animate(e1, _s, _nStep, _nPer[0], _mode);
return(2);
}
function actorf_ani2() {
n1 = actorf_ani1(sAni1, nAniStep, nAniPer, nAniMode);
return(n1);
}
action aPlayer {
wpf_new1(md_wp1, 1, 1);
while(me != NULL) {
// set nAni sAni, etc.
actorf_ani2();
//dump globals back to entity skills
wait(1);
}
}
|
|
|
|