Game Development Community

Forced/Locked 3rd POV During Melee

by Jon Jorajuria · in Torque Game Engine · 11/29/2005 (4:10 pm) · 0 replies

Forced/Locked 3rd POV During Melee

I was looking all around for a way to lock my toons in 3rd POV during melee and I could not find it on the GG boards. I finally figured out how to do it, so I thought I would post what I did for my fellow entry level programmers. This code is based on the functionality in RW and very little of it is my own. All new/changed code is in bold:

In starter.fps/server/scripts/weapon.cs under function Weapon::onUse(%data,%obj) uncomment the following:

//if (%data.itemType $= "melee")
//commandToClient(%obj.client, 'force3rdPerson', 1);
//else
//commandToClient(%obj.client, 'force3rdPerson', 0);

Then change 'force3rdPerson' to 'LockThirdPerson'
The entire code should look like this:

function Weapon::onUse(%data,%obj)
{
// Default behavoir for all weapons is to mount it into the
// this object's weapon slot, which is currently assumed
// to be slot 0

if (%obj.getMountedImage($WeaponSlot) != %data.image.getId()) {
ServerPlay3D(WeaponUseSound,%obj.getTransform());
%obj.mountImage(%data.image, $WeaponSlot);

if (%data.itemType $= "melee")
commandToClient(%obj.client, 'LockThirdPerson', 1);
else
commandToClient(%obj.client, 'LockThirdPerson', 0);
}
}

Next open starter.fps/client/scripts/default.bind.cs
Find the camera and view functions sections.
Below the keymappings add the following code:

$thirdPersonLocked = 0;

function clientCmdLockThirdPerson(%lock)
{
if (%lock)
{
$thirdPersonLocked = 1;
$firstPerson=0;
}
else
{
$thirdPersonLocked = 0;
$firstPerson=1;
}
}

The entire code should look like this:

//------------------------------------------------------------------------------
// Camera & View functions
//------------------------------------------------------------------------------

function toggleFreeLook( %val )
{
if ( %val )
$mvFreeLook = true;
else
$mvFreeLook = false;
}

function toggleFirstPerson(%val)
{
//can't toggle if view is locked
if ($thirdPersonLocked) return;

if (%val)
{
$firstPerson = !$firstPerson;
}
}

function toggleCamera(%val)
{
if (%val)
commandToServer('ToggleCamera');
}

moveMap.bind( keyboard, z, toggleFreeLook );
moveMap.bind(keyboard, tab, toggleFirstPerson );
moveMap.bind(keyboard, "alt c", toggleCamera);


$thirdPersonLocked = 0;

function clientCmdLockThirdPerson(%lock)
{
if (%lock)
{
$thirdPersonLocked = 1;
$firstPerson=0;
}
else
{
$thirdPersonLocked = 0;
$firstPerson=1;
}
}

Now every time you switch to a weapon with itemType="melee" indicated in that weapon's *.cs file, you will be force and locked into 3rd person perspective.