How to stop a moving TransformGroup?

Dear all,
my problem is that I am using a keyboard to navigate a transformgroup object
the class implements KeyEventDispatcher
Below is the example of the coding

              if(ycounter>3.7 && ycounter<4.83)
		{
			x = -(Math.cos(xcounter)*Math.cos(ycounter));
			y = -(Math.sin(xcounter));
			z = -(Math.sin(xcounter)*Math.sin(ycounter));

				n = new Vector3d(v.x+x,v.y+y,v.z+z);
								
				if((v.x+x<15)||(v.x+x>-15)||(v.z+z>-15)||(v.z+z>-15))
				{
				T3.setTranslation(n);
			
				T3.setScale(0.9); // Add this line here to do the real SCALE
				[b]transformGroup[/b]View.setTransform(T3);
				}
					
how do I stop the movement, for example if the z coordinate reaches 10?

Thanks a lot

I assume this is happening in a Behaviour and that x, y and z represent the current location of the transformgroup?

It looks like you have some kind of check for the parameters hitting 15 in there already.

You can pretty much just run with something like


if ( z < 10 )
{
   if ( 3.7 < yCounter  && yCounter < 4.83 )
   {
     <snip>
   }
}

If your conditions are more complex then you’ll perhaps want to create test variables for it:


bool zSafe= -10 < z &&  z < 10;
if (zSafe)
{
  <snip>
}

Much easier to follow that way than having a lot of variables in a long string.

Again, using a magic numbers in your code is a bad idea- much better to create a variable so that you only have to change it once and you know what it represents:


private static int Z_MIN=-10;   // Explanation of why this is the minimum value of z
private static int Z_MAX=10;    // Explanation of why this is the maximum value of z
<snip>
bool zSafe= Z_MIN < z &&  z < Z_MAX;
if (zSafe)
{
  <snip>
}

If you start approaching things this way you will find it much easier to read your code when you need to go back to it. Write for readability first - you can always optimise later if the need arises.