variable speed changes

Posted By: rtsgamer706

variable speed changes - 11/13/13 13:45

Hi, I am working on a project in which I have an entity and every few frames it fires our another entity.
What I want this other entity to do is to move forward for 50 frames and then reverse direction.
here's the action that I am using:
Code:
action pulse()
{
	var dist_test = 0;
	var move_dir = 85;
	my.pan = you.direction;
	set(my, PASSABLE);
	while (my)
	{
		c_move (me, vector(move_dir*time_step, 0, 0), nullvector, IGNORE_PASSABLE);
		dist_test ++;
		if (dist_test == 50)
		{
			move_dir = -85;
			wait(-1);
		}
		wait(1);
	}
}



it does exactly what I want it to the first time
but every subsequent time it reverses direction much faster than the first.
I'm not 100% sure, but I think it's because the "dist_test" var is changes faster, but I have no idea why that would be happening.
I don't have any global variables that could be effecting them, so I don't know how they can act differently.
Thanks
Posted By: Ch40zzC0d3r

Re: variable speed changes - 11/13/13 14:14

You should use time_step instead of dist_test++ wink
And dont use == for these kind oft thinhs use >=
Posted By: rtsgamer706

Re: variable speed changes - 11/13/13 14:39

The >= thing is fine
but what do you mean by use time_step?
I'm using dist_test as a counter, isn't time_step a constant?
Posted By: Ch40zzC0d3r

Re: variable speed changes - 11/13/13 15:04

instead of increasing dist_test every frame by 1 (dist_test ++;)
use dist_test += time_step.
Posted By: rtsgamer706

Re: variable speed changes - 11/13/13 15:09

time_step fixed it
good to know, thanks
© 2024 lite-C Forums