Game Development Community

loop causes clumping or unwanted grouping

by rennie moffat · in iTorque 2D · 10/24/2011 (11:53 am) · 2 replies

Hi there,
I have a behavior, launching projectiles. It works, however, to a degree. That degree, or flaw as I see it is that when the projectiles are released, the funtion runs thru which of the half dozen projectiles are non active, thus available. Upon loading any projectile and firing, a short schedule is created and a new projectile can not be loaded and fired until the schedule is cleared. However, I get bucnching. Not a smooth, consitent stream of projectiles. For instance numbers 2 and 3 will go virtually at the same time. Can someone please look over this code and tell me if they spot the reason?

Much obliged.


function fireProjectile()
{
if(projectil1Active == false)
{
////load and fire;
%this.schedule(%this.time, fireProjectile);
return;
}
if(projectil2Active == false)
{
////load and fire;
%this.schedule(%this.time, fireProjectile);
return;
}
if(projectil3Active == false)
{
////load and fire;
%this.schedule(%this.time, fireProjectile);
return;
}
if(projectil4Active == false)
{
////load and fire;
%this.schedule(%this.time, fireProjectile);
return;
}
if(projectil5Active == false)
{
////load and fire;
%this.schedule(%this.time, fireProjectile);
return;
}
if(projectil6Active == false)
{
////load and fire;
%this.schedule(%this.time, fireProjectile);
return;
}
}

About the author

My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.


#1
10/24/2011 (2:15 pm)
Rennie, difficult to say without seeing the rest of the code around it ...

- what happens to %this.time, does it get incremented?

- when do the flags get set to say projectile has fired?

If you wanted the projectiles half a second apart and you called fireProjectile six times then you would need to make sure %this.time was set as follows:

500
1000
1500
2000
2500
3000
#2
10/24/2011 (2:23 pm)
right. well, here is the actual code.
All of my status checks, proj1 ect, come in accurately. I even placed in a count just to check when what was happening... the issue was, and is, between 2 & 3, and 4 & 5 projectiles. These two groups shoot off almost virtually together. It is very wierd.


As you can see, I am just using a solid state, static, schedule value. My belief is that if projX is fired xSchedultTime pasess, then it looks for which projectile is next. I would think that would be good enough to keep the flow constant.. consistent/even rather.


??


this is a 3 piece chunk. all projectiles are listed off in virtual identical patterns. How this chunk potentially cause a glitch?

if(%proj1Status.active == false)
	{
		%this.proj1.setPosition(%this.owner.position);
		%this.proj1.setLinearVelocityY(%this.bulletSpeed);
		%this.schedule(%this.gunSc, fireProjectiles);
		echo("theMimmicer_behavior::fireProjectiles:: fireProjectiles proj1 ***");
		echo("theMimmicer_behavior::fireProjectiles:: fireProjectiles proj1 %this.count " @ %this.count);
		return;
	}
	else if(%proj2Status.active == false)
	{
		%this.proj2.setPosition(%this.owner.position);
		%this.proj2.setLinearVelocityY(%this.bulletSpeed);
		%this.schedule(%this.gunSc, fireProjectiles);
		echo("theMimmicer_behavior::fireProjectiles:: fireProjectiles proj2 ***");
		echo("theMimmicer_behavior::fireProjectiles:: fireProjectiles proj2 %this.count " @ %this.count);		
		return;
	}
	else if(%proj3Status.active == false)
	{
		%this.proj3.setPosition(%this.owner.position);
		%this.proj3.setLinearVelocityY(%this.bulletSpeed);
		%this.schedule(%this.gunSc, fireProjectiles);
		echo("theMimmicer_behavior::fireProjectiles:: fireProjectiles proj3 ***");
		echo("theMimmicer_behavior::fireProjectiles:: fireProjectiles proj3 %this.count " @ %this.count);		
		return;
	}