changing skin during movement.

Posted By: Realspawn

changing skin during movement. - 06/21/16 17:33

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 laugh
Posted By: Anonymous

Re: changing skin during movement. - 06/21/16 18:25

if the model has all skins packed into the mdl file than.

Code:
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.htm
manual example
Code:
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
Code:
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);
}

Posted By: Realspawn

Re: changing skin during movement. - 06/21/16 18:31

will have a go on this laugh
Posted By: Anonymous

Re: changing skin during movement. - 06/21/16 18:42

Working

flip_rate = highvaule == slow change or lowvalue == fast change

OLD CODE WITH BUG
Click to reveal..
Code:
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);
Code:
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..
Posted By: Realspawn

Re: changing skin during movement. - 06/21/16 18:50

why conecting it to speed ? laugh
Posted By: Anonymous

Re: changing skin during movement. - 06/21/16 18:53

Quote:
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
Posted By: Anonymous

Re: changing skin during movement. - 06/21/16 18:58

Change code to fix crash == division by 0

changed lines - added key input - added division by 0 check
Code:
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;

Posted By: Anonymous

Re: changing skin during movement. - 06/21/16 19:08

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;

Code:
///////////////////////////////
#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;
Posted By: Realspawn

Re: changing skin during movement. - 06/22/16 08:37

still amazed how much lines are needed for stuff
that look so simple laugh
Posted By: Realspawn

Re: changing skin during movement. - 06/22/16 15:18

got it to work laugh thx malice
Posted By: Anonymous

Re: changing skin during movement. - 06/22/16 16:55

Quote:
still amazed how much lines are needed for stuff
that look so simple


Well there is bad coding that just uses to many lines. There are also times when coders make things over complex. There is bad coding that uses to little lines, it focuses only on a simple goal and ignores many other needed cases.

When it comes to answering a question like this or dealing with someone's idea, I tend to have little design information to work from and no hands on time with the project. I like to focus only the cases I have to, but I don't want to keep reworking or supporting a code snip because need design cases appear that were not originally disclosed.
The manual example is the simplest. And you can modify it with only one case in mind.
Case - Flip 3 skins on only one entity, every second, only while the entity is moving.
That would look like this.
Code:
//...STUFF
while (1)
  {
// ... STUFF for  keys
    if(vSpeed) // are keys press and mul by a speed
     {
    my.skin = my.skill1 % 3;// only 3 skins // 32 Skins
    my.skill1 += time_step/5.33; // 16 ticks / by 3 skins == 5.33 // 16 skins per second
     }
    wait (1);
  }


Notes - This is time based, 3 skins flip ever 1 second. This has a bug where skin == 0, but skin should always be 1 or greater. "Lol manual example with a bug"

So in the end I explored more cases beyond this. However I'm sure the code I wrote is , well.., QnD
© 2024 lite-C Forums