|
changing skin during movement.
#460251
06/21/16 17:33
06/21/16 17:33
|
Joined: Jul 2001
Posts: 4,801 netherlands
Realspawn
OP
Expert
|
OP
Expert
Joined: Jul 2001
Posts: 4,801
netherlands
|
I want to change the models skin 3 times in a loop during movement what would be the best way ? using ent_morphskin ? anyone can provide an example ? thx
|
|
|
Re: changing skin during movement.
[Re: Realspawn]
#460253
06/21/16 18:25
06/21/16 18:25
|
Malice
Unregistered
|
Malice
Unregistered
|
if the model has all skins packed into the mdl file than.
var time_change=0;
while(1)
{
time_change+=time_step/16;
if(time_change>1)
{
time_change+=1;
my.skin+=1;
}
if(time_change>=3)
time_change=0;
wait(1);
}
changes skins every second for 3 skins basically my.skin+=nX http://www.conitec.net/beta/aentity-skin.htmmanual example
action flipskins()
{
while (1)
{
my.skin = my.skill1 % 32; // 32 Skins
my.skill1 += time_step; // 16 skins per second
wait (1);
}
}
Going to check this for errors after posting
var dist_to_move=0;
var skin_count=0;
// vSpeed = movement speed;
while(1)
{
// ...STUFF
dist_to_move=(vSpeed*3)*time_step;
skin_count=vSpeed/dist_to_move;
c_move(my,vector(vSpeed*time_step,nX,nX),nullvector,STUFF);
my.skin=integer(skin_count);
wait(1);
}
Last edited by Malice; 06/21/16 18:34.
|
|
|
Re: changing skin during movement.
[Re: Realspawn]
#460255
06/21/16 18:42
06/21/16 18:42
|
Malice
Unregistered
|
Malice
Unregistered
|
Working flip_rate = highvaule == slow change or lowvalue == fast change OLD CODE WITH BUG
action my_action()
{
set(my,SHADOW|CAST);
var dist_to_move=0;
var skin_count=0;
var vSpeed=2;
int flip_rate=18;
while(1)
{
dist_to_move=(vSpeed*flip_rate)*time_step;
skin_count+=(vSpeed*time_step)/dist_to_move;
skin_count%=3;
c_move(my,vector(vSpeed*time_step,0,0),nullvector,GLIDE);
my.skin=integer(skin_count);
wait(1);
}
}
Need to check this line skin_count%=3; ??is returning 1-3 or 0-2????? EDIT - Yes error in code ... New code below EDIT2 - Code notes - vSpeed should == 0 if no key input so like vSpeed = nX*(key_w-key_s);
action my_action()
{
set(my,SHADOW|CAST);
var dist_to_move=0;
var skin_count=0;
var vSpeed=2;
int flip_rate=18;
while(1)
{
dist_to_move=(vSpeed*flip_rate)*time_step;
skin_count+=(vSpeed*time_step)/dist_to_move;
skin_count%=4;
c_move(my,vector(vSpeed*time_step,0,0),nullvector,GLIDE);
my.skin=clamp(integer(skin_count),1,3);//integer(skin_count);
DEBUG_VAR(my.skin,50);
wait(1);
}
}
AS Always QnD code could be better..
Last edited by Malice; 06/21/16 18:52.
|
|
|
Re: changing skin during movement.
[Re: Realspawn]
#460257
06/21/16 18:53
06/21/16 18:53
|
Malice
Unregistered
|
Malice
Unregistered
|
I want to change the models skin 3 times in a loop during movement what would be the best way ? connected to speed because "during movement" So skin changes as a fraction of the distance moved at flip_rate number of frames. It's not connected to speed really, it's connected to distance traveled See final edits above
Last edited by Malice; 06/21/16 18:54.
|
|
|
Re: changing skin during movement.
[Re: ]
#460258
06/21/16 18:58
06/21/16 18:58
|
Malice
Unregistered
|
Malice
Unregistered
|
Change code to fix crash == division by 0 changed lines - added key input - added division by 0 check
vSpeed=2*(key_w-key_s);
dist_to_move=(vSpeed*flip_rate)*time_step;
if(dist_to_move)
skin_count+=(vSpeed*time_step)/dist_to_move;
|
|
|
Re: changing skin during movement.
[Re: ]
#460259
06/21/16 19:08
06/21/16 19:08
|
Malice
Unregistered
|
Malice
Unregistered
|
LOL - I'm bored!! Best and last version but still QnD code Code changes - removed clamp -- caused 1 to play double -added back the %=3 modulo -- http://www.conitec.net/beta/avar-Ref.htm- corrected the skin== 0 by adding +1 to my.skin = int(xN)+1;
///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////
action my_action()
{
set(my,SHADOW|CAST);
var dist_to_move=0;
var skin_count=0;
var vSpeed=2;
int flip_rate=30;
while(1)
{
vSpeed=2*(key_w-key_s);
dist_to_move=(vSpeed*flip_rate)*time_step;
if(dist_to_move)
skin_count+=((vSpeed*time_step)/dist_to_move);
skin_count%=3;
c_move(my,vector(vSpeed*time_step,0,0),nullvector,GLIDE);
my.skin=integer(skin_count)+1;//clamp(integer(skin_count),1,3);
DEBUG_VAR(my.skin,50);
wait(1);
}
}
function main()
{
vec_set(screen_size,vector(800,400,0));
vec_set(screen_color,vector(50,1,1)); // dark blue
vec_set(sky_color,vector(50,1,1)); // dark blue
video_window(NULL,NULL,0,"My New Game");
d3d_antialias = 1;
shadow_stencil = 3;
fps_max=60;
level_load("tTest.wmb");
vec_set(camera.x,vector(-250,0,50));
vec_set(camera.pan,vector(0,-15,0));
}
Known issues - skin always flips in a cycle 1-3, can not reverse 3-1. probable cause - skin_count%=3;
Last edited by Malice; 06/21/16 19:13.
|
|
|
|