Iron Sights for Torque3D 1.2
by deepscratch · 12/18/2011 (5:17 am) · 25 comments
I've always loved using Iron Sights, especialy as I dont like using any ingame huds or gui's or crosshairs.
howTo get them working:
1; BACKUP FILES FIRST!!!!
2; find in lurker.cs and ryder.cs the line
and this for the ryder
3; open game/scripts/server/commands.cs, and add these 2 functions to the end of the file
4; now open game/scripts/client/client.cs, and add these 2 functions at the end of the file
5; next you'll need to open up game/scripts/client/default.bind.cs, and add this function to the end of the file
6; almost done, find this line in default.bind.cs
and you're ready to use Iron Sights with the Lurker and Ryder weapons. press the right mouse button to use the Iron Sights and release the button to return to normal view.
NOTE: the FP arms/weapon models are slightly offset to the left of centre screen, so the weapons are shooting slightly to the right. If anyone can find a way to get them to centre screen, please share your solution here.
pictures in action:


enjoy
howTo get them working:
1; BACKUP FILES FIRST!!!!
2; find in lurker.cs and ryder.cs the line
animateOnServer = true;then directly below that line, add this for the lurker
// Iron Sights begin useEyeOffset = false; eyeOffset = "0.1 0.4 -0.35"; DoIronSights = true; ReturnPosition = "0.01 0.25 -0.42"; IronSightsPosition = "-0.147 -0.225 0.025"; // Iron Sights end
and this for the ryder
// Iron Sights begin useEyeOffset = false; eyeOffset = "0.1 0.4 -0.35"; DoIronSights = true; ReturnPosition = "0.01 0.25 -0.42"; IronSightsPosition = "-0.1815 -0.25 0.0495"; // Iron Sights end
3; open game/scripts/server/commands.cs, and add these 2 functions to the end of the file
//------------------------------------------------------------------------------
// iron sights functions
//------------------------------------------------------------------------------
function serverCmdDoIronSights(%client,%val)
{
%curWeapon = %client.player.getMountedImage($WeaponSlot);
%offset = %curWeapon.IronSightsPosition;
%canDoIronSights = %curWeapon.DoIronSights;
if(%canDoIronSights)
{
%curWeapon.firstPerson = false;
%curWeapon.useEyeNode = false;
%curWeapon.animateOnServer = false;
commandToClient(%client,'DoIronSights',%client,%curWeapon,%offset);
%weaponName = %curWeapon.item.getName();
echo("-->Selected Weapon is " @ %weaponName);
}
else if(!%canDoIronSights)
{
echo("-->Weapon does not have Iron Sights");
return;
}
}
//-----------------------------------------------------------------------------
function serverCmdUndoIronSights(%client,%val)
{
%curWeapon = %client.player.getMountedImage($WeaponSlot);
%offset = %curWeapon.ReturnPosition;
%canDoIronSights = %curWeapon.DoIronSights;
if(%canDoIronSights)
{
%curWeapon.firstPerson = true;
%curWeapon.useEyeNode = true;
%curWeapon.animateOnServer = true;
commandToClient(%client,'UndoIronSights',%client,%curWeapon,%offset);
}
else if(!%canDoIronSights)
{
return;
}
}4; now open game/scripts/client/client.cs, and add these 2 functions at the end of the file
//------------------------------------------------------------------------------
// iron sights functions
//------------------------------------------------------------------------------
function clientCmdDoIronSights(%client,%curWeapon,%offset)
{
%curWeapon.eyeOffset = %offset;
echo("-->Adjusting EyeOffset to " @ %offset);
}
function clientCmdUndoIronSights(%client,%curWeapon,%offset)
{
%curWeapon.eyeOffset = %offset;
echo("-->Returning EyeOffset to " @ %offset);
}5; next you'll need to open up game/scripts/client/default.bind.cs, and add this function to the end of the file
//------------------------------------------------------------------------------
// iron sights functions
//------------------------------------------------------------------------------
moveMap.bind( mouse, button1, toggleIronSights );
function toggleIronSights( %val )
{
$mvTriggerCount1++;
if ( %val == 1 )
{
$ZoomOn = true;
commandToServer( 'DoIronSights' );
reticle.setVisible(false);
}
else if ( %val == 0 )
{
$ZoomOn = false;
commandToServer( 'UndoIronSights' );
reticle.setVisible(true);
}
}6; almost done, find this line in default.bind.cs
moveMap.bind( mouse, button1, mouseButtonZoom );and replace it with
//moveMap.bind( mouse, button1, mouseButtonZoom );
and you're ready to use Iron Sights with the Lurker and Ryder weapons. press the right mouse button to use the Iron Sights and release the button to return to normal view.
NOTE: the FP arms/weapon models are slightly offset to the left of centre screen, so the weapons are shooting slightly to the right. If anyone can find a way to get them to centre screen, please share your solution here.
pictures in action:


enjoy
About the author
email me at medan121@gmail.com
#2
12/18/2011 (4:02 pm)
Great post should be in T3D as default.
#3
12/18/2011 (8:29 pm)
Brilliant.
#4
12/19/2011 (4:16 pm)
I like this. Very nice!
#5
12/20/2011 (10:52 am)
Once again, deepscratch is the man!!! I cant wait to buy T3d1.2 next month......
#6
Great work deepscratch.
12/20/2011 (11:35 am)
I like this... alot. I'll be sure this gets into my FPS project :DGreat work deepscratch.
#9
Anyone figure a way around this yet?
12/27/2011 (3:32 pm)
Nice work, appreciate you sharing this with us, however, cannot seem to figure out how to line up the sights so that the impact isn't 2 feet right of the sights. Would really like to use this in a FPS game, but is really useless if the aim is off.Anyone figure a way around this yet?
#10
12/29/2011 (11:44 pm)
I am so looking forward to adding this to my project! Thanks deepscratch. Jim seems to be right though, even in the above screens the sights aren't aligning with the impact. Having said that however, I can't hit what I'm shooting at now! Haha... This will work perfectly until we work out the camera/projectile offset issue.
#11
useEyeOffset = false;
eyeOffset = "0.1 0.4 -0.35";
DoIronSights = true;
ReturnPosition = "0.01 0.25 -0.42";
IronSightsPosition = "-0.147 -0.225 0.025";
// Iron Sights end
the eyeOffset = "0.1 0.4 -0.35"; might need to be something like 0.1 0.2 -0.35 I'm thinking.
12/30/2011 (9:47 pm)
// Iron Sights beginuseEyeOffset = false;
eyeOffset = "0.1 0.4 -0.35";
DoIronSights = true;
ReturnPosition = "0.01 0.25 -0.42";
IronSightsPosition = "-0.147 -0.225 0.025";
// Iron Sights end
the eyeOffset = "0.1 0.4 -0.35"; might need to be something like 0.1 0.2 -0.35 I'm thinking.
#12
should I new those?
where should I place them?
01/05/2012 (5:23 am)
I do not have the files(lurker.cs and ryder.cs)should I new those?
where should I place them?
#13
should I new those?
where should I place them?
01/05/2012 (5:28 am)
I do not have the files(lurker.cs and ryder.cs)should I new those?
where should I place them?
#14
"C:/Torque/Torque 3D 1.2/templates/full/game/art/datablocks/weapons"
It's setup looks like it should work for multiplayer but I'm not getting any results using a dedicated server, has anyone else tried multiplayer with this yet?
P.S. for extra rotation controls here's the commands.cs:
and heres the clients.cs:
01/07/2012 (1:06 am)
@Michael: You need T3D 1.2 to use this resource and they are located inside: "C:/Torque/Torque 3D 1.2/templates/full/game/art/datablocks/weapons"
It's setup looks like it should work for multiplayer but I'm not getting any results using a dedicated server, has anyone else tried multiplayer with this yet?
P.S. for extra rotation controls here's the commands.cs:
function serverCmdDoIronSights(%client,%val)
{
%curWeapon = %client.player.getMountedImage($WeaponSlot);
%offset = %curWeapon.IronSightsPosition;
%rotation = %curWeapon.IronSightsRotation;
%canDoIronSights = %curWeapon.DoIronSights;
if(%canDoIronSights)
{
%curWeapon.firstPerson = false;
%curWeapon.useEyeNode = false;
%curWeapon.animateOnServer = false;
commandToClient(%client,'DoIronSights',%client,%curWeapon,%offset,%rotation);
%weaponName = %curWeapon.item.getName();
echo("-->Selected Weapon is " @ %weaponName);
}
else if(!%canDoIronSights)
{
echo("-->Weapon does not have Iron Sights");
return;
}
}
//-----------------------------------------------------------------------------
function serverCmdUndoIronSights(%client,%val)
{
%curWeapon = %client.player.getMountedImage($WeaponSlot);
%offset = %curWeapon.ReturnPosition;
%rotation = %curWeapon.ReturnRotation;
%canDoIronSights = %curWeapon.DoIronSights;
if(%canDoIronSights)
{
%curWeapon.firstPerson = true;
%curWeapon.useEyeNode = true;
%curWeapon.animateOnServer = true;
commandToClient(%client,'UndoIronSights',%client,%curWeapon,%offset,%rotation);
}
else if(!%canDoIronSights)
{
return;
}
}and heres the clients.cs:
//------------------------------------------------------------------------------
// iron sights functions
//------------------------------------------------------------------------------
function clientCmdDoIronSights(%client,%curWeapon,%offset,%rotation)
{
%curWeapon.eyeOffset = %offset;
%curWeapon.eyeRotation = %rotation;
echo("-->Adjusting Eye Position to " @ %offset @ ":" @ %rotation);
}
function clientCmdUndoIronSights(%client,%curWeapon,%offset,%rotation)
{
%curWeapon.eyeOffset = %offset;
%curWeapon.eyeRotation = %rotation;
echo("-->Returning Eye Position to " @ %offset @ ":" @ %rotation);
}
#15
I had to set the Lurker up like this to get it working with the above rotations.
EDIT. Ask question.
Is there a way to get the crosshair to show up while in the editor?
Thanks
01/07/2012 (7:39 am)
Hi,I had to set the Lurker up like this to get it working with the above rotations.
// Iron Sights begin useEyeOffset = false; eyeOffset = "0.1 0.4 -0.35"; DoIronSights = true; ReturnPosition = "0.01 0.25 -0.42"; IronSightsPosition = "-0.147 -0.225 0.025"; IronSightsRotation = "0.0341409 0.0968478 0.994713 2.93321"; // Iron Sights endStill a bit off but I have not try'ed this with dedicated server.
EDIT. Ask question.
Is there a way to get the crosshair to show up while in the editor?
Thanks
#16
01/10/2012 (5:15 pm)
To get rid of the right-offset shooting, set correctMuzzleVector in each weapon image to false.
#17
Added code tags.
Well its almost correct lol
01/23/2012 (6:16 pm)
I found the correct settings for Ryder pistle with using correctMuzzleVector = true;// Iron Sights begin useEyeOffset = true; eyeOffset = "0 0 0"; DoIronSights = 1; ReturnPosition = "0 0 0"; IronSightsPosition = "-0.19488 -0.3 0.049"; IronSightsRotation = "0.405853 0 0.913938 3.80559"; // Iron Sights endComment:
Added code tags.
Well its almost correct lol
#18
EDIT. Add code tags.
01/23/2012 (6:38 pm)
Heres one for the lurkerEDIT. Add code tags.
// Iron Sights begin useEyeOffset = 0; eyeOffset = "0 0 0"; DoIronSights = 1; ReturnPosition = "0 0 0"; IronSightsPosition = "-0.16 -0.26 0.06"; IronSightsRotation = "0.574892 0.0910342 0.813149 4.72198"; // Iron Sights end
#19
02/08/2012 (10:34 am)
So, I followed the first steps exactly to try to get the aiming to work as pictured, but was unable to see any kind of change at all to the FPS Tutorial. Any ideas why this would not work for me?? Thanks
#20
both files are in the game/scripts/client folder.
02/08/2012 (2:32 pm)
A common problem when making changes to your default.bind.cs file is that you have to delete your config.cs file so it can be regenerated and affect any changes you have made, I'd try that and see if it works.both files are in the game/scripts/client folder.

Torque Owner Stephen
GearedMind Studio