Game Development Community

Hiding Crosshair

by none · in Torque Game Engine · 03/24/2011 (9:39 pm) · 5 replies

I have an iron sights implemented into my game, but I want the crosshair to disappear when I activate it. There is no zoom involved with my iron sights. I'm using TGE 1.5.2. Can someone please help me to get this working?
moveMap.bind(mouse0, "button2", toggleEyeOffset);  

function toggleEyeOffset( %val )  
{  
   if ( %val == 1 )  
      commandToServer( 'AdjustEyeOffset' ); 
      Crosshair.setVisible(AdjustEyeOffset); 
      
   else if ( %val == 0 )  
      commandToServer( 'ReturnEyeOffset' );
     
}

function clientCmdAdjustEyeOffset(%client,%curWeapon,%offset)  
{  
   %curWeapon.eyeOffset = %offset;  
   echo("-->Adjusting EyeOffset to " @ %offset);  
}  
  
function clientCmdReturnEyeOffset(%client,%curWeapon,%offset)  
{  
   %curWeapon.eyeOffset = %offset;  
   echo("-->Returning EyeOffset to " @ %offset);  
}

#1
03/24/2011 (9:58 pm)
Isn't it %guiElement.setVisible(bool)?

Also make it a serverCommand if you want this networking, you should be able to leave it as it is for single player on the same box though.
#2
03/24/2011 (10:18 pm)
What Steve said. Assuming your GuiCrossHairHud is named:
GuiCrossHairHud(Reticle)
Just call
Reticle.setVisible(false);
Reticle.setVisible(true);
as needed with the appropriate server/client CMD's.
#3
03/25/2011 (6:25 am)
Thanks for the quick replies guys! I will try this as soon as I get home today!
#4
03/25/2011 (4:35 pm)
In default.bind.cs:

moveMap.bind(mouse0, "button2", toggleEyeOffset);  
function toggleEyeOffset( %val )  
{  
   if ( %val == 1 )  
      commandToServer( 'AdjustEyeOffset' );       
   else if ( %val == 0 )  
      commandToServer( 'ReturnEyeOffset' );
}

In client/scripts/client.cs:

function clientCmdAdjustEyeOffset(%client,%curWeapon)  
{  
   //%curWeapon.eyeOffset = %offset;  
   // ^bad!
   echo("-->Adjusting EyeOffset");  
   Crosshair.setVisible(false);
   $sightAim = true;
}
function clientCmdReturnEyeOffset(%client,%curWeapon)  
{  
  // %curWeapon.eyeOffset = %offset;  
  // ^bad!
   echo("-->Returning EyeOffset");  
   Crosshair.setVisible(true);
   $sightAim = false;
}

In server/scripts/commands.cs:

function serverCmdAdjustEyeOffset(%client)
{
   CommandToClient(%client,'AdjustEyeOffset',%client.player.getMountedImage($WeaponSlot));
}
function serverCmdReturnEyeOffset(%client)
{
  CommandToClient(%client,'ReturnEyeOffset',%client.player.getMountedImage($WeaponSlot));
}

For full network capability, I recommend digging into the shapeImage rendering code and duplicating eyeOffset so you have something like a sightOffset to work with.
In ShapeBase::getRenderImageTransform(U32 imageSlot,MatrixF* mat), the eyeOffset matrix transformation is done. In the code above, I set a variable called "$sightAim" to true. So then, in the if (data.useEyeOffset) section, you could do something like this:

if (Con::getBoolVariable("$sightAim") == true)
  mat->mul(nmat,data.sightOffset);
else
  mat->mul(nmat,data.eyeOffset); // That should already be there

If the global variable $sightAim is set to true, then the code will offset the weapon by your image's sightOffset instead. Otherwise, it will render normally.
#5
03/25/2011 (5:00 pm)
Thank you so much Bryce! This will help me so much!