The current built-in system is decent for some cases, but, when huge levels are involved (exceeding 60,000 quants in diameter), it can take several minutes to get to the other side of the level. Then, the fast motion from the sudden acceleration makes it tricky to get the camera in a certain spot. The best solution is to utilize acceleration. At first, the camera starts off slowly, allowing for fine movement. If the up arrow key is held for extended time, the camera keeps on accelerating thus being able to get 500,000 quants from the level's origin in only about a minute or so. Then, from here, one could fine-tune their positioning from this far out. All that's needed is a behavior like this:

Code:

function accel_camera()
{
var horiz_speed[2] = 0, 0; // old then new speeds
var vertic_speed[2] = 0, 0; // old then new speeds for vertical movement
var cam_dist = 0; // camera distance

while(1)
{
// First, we'll establish the camera angle.
if ((key_cul == on) || (key_cur == on)) // if turning the camera
{
if ((key_cul == on) && (key_cur == off)) // left is positive in Euler angles
{
camera.pan += 5.625*time;
}

if ((key_cul == off) && (key_cur == on)) // right is negative in Euler angles
{
camera.pan -= 5.625*time; // turns 16*11.25 or 180 degrees per second
}

if (camera.pan < 0)
{
camera.pan += 3600; // make positive
}

camera.pan %= 360; // keep within range of 0 to 360
}

if ((key_pgup == on) || (key_pgdn == on)) // if tilting the camera
{
if ((key_pgup == on) && (key_pgdn == off)) // pitching upwards
{
camera.tilt += 5.625*time; // tilt the camera upwards
}

if ((key_pgup == off) && (key_pgdn == on)) // pitching downwards
{
camera.tilt -= 5.625*time; // tilt the camera downwards
}

camera.tilt = clamp(camera.tilt, -90, 90); // can't tilt camera beyond straight down and straight up
}

// Next, we'll move the camera based on that angle
if ((key_cuu == on) || (key_cud == on)) // if moving
{
horiz_speed[0] = horiz_speed[1]; // record previous speed
horiz_speed[1] += (3.667*time); // update current speed for acceleration
cam_dist = (horiz_speed[0] + horiz_speed[1])/2*time; // average speed and find distance to travel

if ((key_cuu == on) && (key_cud == off)) // one key can be pressed - up is forward
{
camera.x += cos(camera.pan)*cam_dist*cos(camera.tilt); // move camera accordingly
camera.y += sin(camera.pan)*cam_dist*cos(camera.tilt);
camera.z += sin(camera.tilt)*cam_dist; // if going up, move the camera up
}

if ((key_cuu == off) && (key_cud == on)) // one key can be pressed - down is backward
{
camera.x -= cos(camera.pan)*cam_dist*cos(camera.tilt); // move camera accordingly
camera.y -= sin(camera.pan)*cam_dist*cos(camera.tilt);
camera.z -= sin(camera.tilt)*cam_dist; // backwards is the reverse
}
}

if ((key_cuu == off) && (key_cud == off)) // reset speed if no position-changing key is used
{
horiz_speed[0] = 0;
horiz_speed[1] = 0;
cam_dist = 0;
}

wait(1);
}
}



This makes it easier for getting around huge levels and fine-tuning positioning. The rotations, however, need some adjustments though. With this small piece of code, you could get around huge levels easily and quickly and you can fine-tune the positioning more easily as well. I think walk-through mode should use something similar. Currently, it's a slow 20 mph constant speed (8 quants to 1 foot map scale) or 40 mph if the shift keys are held, too slow for huge levels. With this, topping 3000 mph is easy which is why it helps. Could, in some future update, Gamestudio have this similar behavior built-in?

Edit: 3.667 is 80 mph per second per second acceleration where your map scale is 8 quants to 1 foot

Last edited by ulillillia; 07/24/06 10:44.

"You level up the fastest and easiest if you do things at your own level and no higher or lower" - useful tip My 2D game - release on Jun 13th; My tutorials