Game Development Community

Script help

by Lars Boldt · in Torque Game Engine · 08/01/2004 (6:30 pm) · 8 replies

Ok i'm sure this is a very simple thing but this is my first time scripting with torque so...

I've implemented the advance camera resource and i'm trying to make a function that will switch camera mode whenever I press C.


game.cs

function switchCam()
{
%this.advCamera.setPlayerObject(%player);
%this.advCamera.setGodViewMode();
%this.advCamera.setFollowTerrainMode(false);
%this.setCameraObject(%this.advCamera);
}


default.bind.cs

moveMap.bindCmd(keyboard, "c", "", "switchCam();");


Now the switchCam function isn't working because obviously the pointer %this is lost somewhere and has no value in my function.

I've ordered a book about this stuff so I will eventually get the logic here but right now I just need some mini help until ze book arrives :)

Oh and is there anything like a RenderText(String, PosX, PosY) function in Torque script?

I wanted to make it say like God Mode View in the middle of the screen with some cool font of choice whenever I switched camera mode. Also I want this when I move around on the map and enter different sections of the map.

Thanks

Lars

#1
08/01/2004 (9:46 pm)
I would store the camera in a global somewhere. Or you might have to do a commandToServer to do it.

No, but you can place a GuiTextControl to get the same effect.
#2
08/02/2004 (5:05 am)
Thanks Ben, that got me abit further.

Game.cs

function switchCam($CamObj, $playObj)
{    
   $CamObj.advCamera.setPlayerObject($playObj);
   if ($switch == 1)
	{
        $CamObj.advCamera.setThirdPersonMode();
        $CamObj.advCamera.setFollowTerrainMode(false);
	$switch = 2;
	$getCam = "Third Person Mode";
	}
   else if ($switch == 2)
	{
        $CamObj.advCamera.setTrackMode();
        $CamObj.advCamera.setCameraPosition($playObj.getPosition());
	$switch = 3;
  	$getCam = "Tracking Mode";
	}
   else if ($switch == 3)
	{
        $CamObj.advCamera.setGodViewMode();
	$switch = 4;
	$getCam = "God View Mode";
	}
   else if ($switch == 4)
	{
        $CamObj.advCamera.setOrbitMode();
	$switch = 1;
	$getCam = "Orbit Mode";
	}
   $CamObj.setCameraObject($CamObj.advCamera);
}

Now, whenever I press C, it goes through this list and updates the camera.

However, without knowing what I did I chanced on something being called $playObj.getPosition() and it worked. but it's set to the players feet, if I want it 50 or 100 points up from the ground could I easily do that somehow without manipulating the result as a string?

The $getCam is a global I want to show with the GuiTextControl.

My playGui.gui now looks like this:

new GuiTextCtrl() {
      profile = "GuiTextProfile";
      horizSizing = "center";
      vertSizing = "top";
      position = "179 33";
      extent = "134 18";
      minExtent = "20 5";
      visible = "1";
      text = "Current camera is: "+$getCam;
      maxLength = "255";
   };

How do I correctly include variables with strings in Torque script?

Also I wanted to know abit more how to control the font, text size, text color, fade in, fade out effect and so on of the GuiTextControl. I guess it won't have a built in fade-in/fade-out but somehow I need to control the length of the time it's being visible...

In advance thanks!

Lars
#3
08/02/2004 (5:56 am)
How do I correctly include variables with strings in Torque script?


Fixed that, got the update of the GuiTextCtrl working. Still lost on the other things tho :)

Lars
#4
08/02/2004 (7:04 am)
Know how to control the characteristics of the GUI now so only thing left is the $CamObj.advCamera.setCameraPosition($playObj.getPosition()); and raising the Z value with 50-100 points...

Thanks,

Lars
#5
08/02/2004 (7:30 am)
There's a getObjectCenter() call (or something named similar to that) which will return the center position of an object. Or you can use VectorAdd to add 100 units to the z axis.
#6
08/02/2004 (8:59 am)
Found getEyeTransform() which pretty much did the trick.

Now i've run into a new problem which is abit tricky for me to solve :)

function switchCam($CamObj, $playObj)
{    
   $CamObj.advCamera.setPlayerObject($playObj);
   
   if ($switch == 1)
	{
        $CamObj.advCamera.setThirdPersonMode();
        $CamObj.advCamera.setFollowTerrainMode(false);
	$switch = 2;
	$getCam = "Third Person";
	$CamObj.setCameraObject($CamObj.advCamera);
	}
   
   else if ($switch == 2)
	{
        $CamObj.advCamera.setTrackMode();
        $CamObj.advCamera.setCameraPosition($playObj.getEyeTransform());
	$switch = 3;
  	$getCam = "Tracking";
	$CamObj.setCameraObject($CamObj.advCamera);
	}
   
   else if ($switch == 3)
	{
        $CamObj.advCamera.setGodViewMode();
	$switch = 4;
	$getCam = "God View";
	$CamObj.setCameraObject($CamObj.advCamera);
	}
   
   else if ($switch == 4)
	{
        $CamObj.advCamera.setOrbitMode();
	$switch = 5;
	$getCam = "Orbit";
	$CamObj.setCameraObject($CamObj.advCamera);
	}

   else if ($switch == 5)
	{
	$CamObj.camera.setPlayerObject($playObj);
	$CamObj.camera.setTransform($playObj.getEyeTransform());
	$CamObj.setCameraObject($CamObj.camera);
	$switch = 1;
	$getCam = "Normal Third Person";
	}

   camText.setText("Current Camera Mode is: " @ $getCam);
}

In case 5, I want to move back to the normal camera object which comes out of the box with Torque, in Third Person Mode. And if possible detach the camera from the players movement so it doesn't follow the characters breathing, but that's just a plus if I can get that going.

Anyways, any pointers on how to restore normal 3rd person camera, because the code in else if ($switch == 5) only puts the camera at the player position facing like the character does, but it doesn't follow the character...

In advance thanks,

Lars
#7
08/02/2004 (9:39 am)
Btw is this for a multiplayer or single player game? well either way, wouldnt it be easier just to do it with client/server commands?
#8
08/02/2004 (10:16 am)
Single Player. There is no server functionality enabled in my game as far as I know.

It's built on the mini-ap tutorials. Not sure how to get the server commands working since I haven't worked with the network code yet.

Lars