Game Development Community

Stop the Camera at Bounds?

by Glenn Bermingham · in Torque 3D Professional · 09/30/2014 (9:46 pm) · 0 replies

Hey Guys, been working on an top down game, specifically the camera. I'm using the observer camera to navigate around my world but the biggest problem I have with that is I can't for the life of me figure out how to clamp it inside a specified area/zone/cords.

I got the point where I tried to remake the camera movement which (sort of) works but comes with undesired stuttering which is due to the fact I'm literally updating the position of the camera by a small value. Then on top of that its very slow movement to negate the stutter.

Awful unrefined code below, I've attempted to 'smooth' it out using a for loop but now realizing the loop actually applies all of the updates at once (Or so fast it doesn't matter).

//binds.cs
function moveleft(%val)
{
%addx = -0.25;
%addy = 0;
%addz = 0;

if(%val == 1)
{
$moving = true;
commandToServer('MoveCamera', %addx, %addy, %addz);
}
else
$moving = false;
}

//Commands.cs
function serverCmdMoveCamera(%client, %addx, %addy, %addz, %camera)
{
%camera = %client.camera;
//%camera.position = VectorAdd(%camera.position, %addx SPC %addy SPC %addz);
//echo(%client SPC %addx SPC %addy SPC %addz SPC %camera);
if($moving == true)
{
moveCameraDirection( %client, %addx, %addy, %addz, %camera );
//schedule(1, 0, "moveCameraDirection", %client, %addx, %addy, %addz, %camera);
}
else
return;
}

function moveCameraDirection(%client, %addx, %addy, %addz, %camera)
{
%x = %addx / 30; //30 for 30 FPS?
%y = %addy / 30;
%z = %addz / 30;
//echo("Woop: " @ %x SPC %y SPC %z);
for(%i = 0; %i < 30; %i++)
{
//echo("Pos " @ %camera.position);
%camera.position = VectorAdd(%camera.position, %x SPC %y SPC %z);
//%i++;
}
//echo(%camera.position);
commandToServer('MoveCamera', %addx, %addy, %addz, %camera);
}

Ideally I'd like to use the movement that's already applied through $mvLeftAction that just stops at at defined position but I don't know how to do that while the moveLeft button is being held.