Game Development Community

3d side scroller?

by Will Robinson · in Torque Game Engine · 09/20/2007 (8:10 am) · 4 replies

Is it possible to make the camera only move in the x and y axis?

#1
09/22/2007 (4:28 am)
Yes. I did not try with the default camera, but using the advanced camera resource you will be able to place the cam at some angle to your player and have it following your payer as he moves left/right over the screen.
#2
09/22/2007 (7:27 pm)
AWESOME! Thank you so much../



BTW : Sorry posted in the wrong forum....
#3
09/26/2007 (6:50 am)
To help you get started .....
After implementing the advanced camera resource you can try the following.

Add to camera.cs the following datablock.
datablock AdvancedCameraData(AdvCameraData)
{
	lookAtOffset = "0 0 2";
	thirdPersonOffset = "10 0 5";
	godViewOffset = "100 -20 20";
	maxTerrainDiff = 2;
	//orbitOffset	= "10 10 10";
	orbitMinMaxZoom = "5 100";
	orbitMinMaxDeclination = "10 80";
	damping = 0.25;
};

In server/game.cs add.. I did not remove the default camera, dunno if you should or not.
function GameConnection::onClientEnterGame(%this)
{
...
...
	// Create advanced camera
	%this.advCamera = new AdvancedCamera() {
		dataBlock = AdvCameraData;
	};
	MissionCleanup.add(%this.advCamera);
	%this.advCamera.scopeToClient(%this);

...
...
}

function GameConnection::onClientLeaveGame(%this)
{
  	if (isObject(%this.advCamera))
		%this.advCamera.delete();
....
....
}

function GameConnection::createPlayer(%this, %spawnPoint)
{
...
...
...

	// setup cam
  	%this.advCamera.setPlayerObject(%player);
  	%this.advCamera.setOrbitMode();
	%this.advCamera.setOrbitOffset("0 0 0");
	
  	%this.advCamera.setFollowTerrainMode(false);
  	%this.advCamera.setVerticalFreedomMode(false);
  	%this.setCameraObject(%this.advCamera);

}

And then on client side you might want to change the key controls a bit. There are many ways you could do this but here's some of stuff I did to have the player move left/right and be able to jump. (note, I still got the default awsd and other binds in there for the editor to work nice.

You need to press Alt-C and might need to press TAB twice or so to get the camera "loose" from the player when you want to edit the terrain. (I might have messed up a little in toggleFirstPerson())

default.bind.cs
function jump(%val)
{
   $mvTriggerCount2++;
}
function goLEFT(%val)
{
    if(%val) commandToServer('GoLeft');
    $mvForwardAction = %val;
}
function goRIGHT(%val)
{
    if(%val) commandToServer('GoRight');
    $mvForwardAction = %val;
}

moveMap.bind( keyboard, space, jump );
moveMap.bind( keyboard, left,  goLEFT );
moveMap.bind( keyboard, right, goRIGHT );

$firstPerson = true;
function toggleFirstPerson(%val)
{
   //if (%val)
   //{
   //   $firstPerson = !$firstPerson;
   //   ServerConnection.setFirstPerson($firstPerson);
   //}
    if (%val) {
        if( $firstPerson ) {
            $firstPerson = false;
            $pref::Player::SideView = true;
        } else if( $pref::Player::SideView ) {
            $pref::Player::SideView = false;
        } else {
            $firstPerson = true;
        }
			ServerConnection.setFirstPerson($firstPerson);
    }

}



server/commands.cs
function serverCmdGoRight(%client)
{
    if (%client.player) { // only work if client have player (player alive)
        %transf = %client.player.getTransform(); // pos [x,y,z] , rot [x,y,z,angle]

        // now rotate
        %transf = setWord(%transf, 5, "1"); // rot z
        %transf = setWord(%transf, 6, "0.0"); // rot angle
        %client.player.setTransform(%transf);
    }
}

function serverCmdGoLeft(%client)
{
    if (%client.player) { // only work if client have player (player alive)
        %transf = %client.player.getTransform(); // pos [x,y,z] , rot [x,y,z,angle]
        // now rotate
        %transf = setWord(%transf, 5, "1"); // rot z
        %transf = setWord(%transf, 6, "3.141592654"); // rot angle in radians = 180 degrees
        %client.player.setTransform(%transf);
    }
}

This code should have the player running on straight line left/right over screen. Think you just need to check your spawn and make sure its in correct place.. think I placed mine at "0 0 0" and just moved it up/down depending on terrain height.

Well, hope this gives you a point to start from. I would love to work on such a 3D sidescroller sometime but first I need to finish my current projtec ;)
#4
09/26/2007 (6:53 am)
This would make a nice resource on TDN!