Game Development Community

Torque Guide for Newbies

by Simon Goodchild · in Torque Game Engine · 09/14/2007 (9:32 am) · 20 replies

Or the other title for this thread......

"Share my Pain" (and joy when it happens occasionally!!!)

For the record, Torque looks superb, it's my pain, not it's....!)

I found the thread by Christian Siebmanns incredibly helpful, both learning from errors and successes!! So I'm going to do the same, and hopefully pass on anything I learn (both wrong and right!), and glady take any criticism (hopefully constructive, as will to live is often fragile as it is!!)

Ok, take my virtual hand, and join me as we dance (and cry no doubt due to my frequent inability to do what I want) to the tune of Torque...

So what I've done so far...

Downloaded and installed Torque SDK 1.5 (stumping up the $100 feels a bargain to be honest - I work in IT and appreciate the effort involved in the product to date. For the record, thanks to all at GG!).

Depending on where I am (work or home), I have it installed on PC and Mac, so maybe some experiences comparing the enviornment will be included too....!

I've also installed (on both) Torque Constructor. Now, I did have a play with Torque some time, and some versions, ago - and used Quark then. I remember being frustrated, and find Constructor a comparative joy to use. It's not a mega bucks commercial product, but so far as a self-confessed newbie, I like!

What else? Well I've found that I've installed Microsoft Visual C++ 2005 Express Edition - a free download from Microsoft. I've used the Csharp version for a while, and find it a quick (and free) (and pretty good!) editor/compiler. My limited play with this edition makes me feel I'll think this same of this one! You'll see why I've dived (no pun, again see why in a minute) into compiling code shortly!

Okay, apart form a free text editor for Mac, and Notepad for PC that's all I've used.

Oh - I use Fireworks on both as a graphics package. I use this for everything from graphics, to logos, to websites, and love the package. My vote to keep it separate from Photoshop as it's own package is duly made.

Right, having downloaded and installed everything, I did the usual and dived in, and cool - Starter.Fps working. After spending ten minutes chasing that bloody orc, I felt I should try and do something. Now I'm sure I downloaded a copy of the Introductory tutorial, but I'm buggered if I can find it again. But praise to all things Google (how did I cope learning to program pre-internet???!!!), and a quick search found a copy at this web site. Take my advice, download it and print it out!!

Now, I'm not going to reproduce that tutorial, but go through it, digest it (more than I did), and take your time (not like me). Having got that far I decided that I could finally do what I wanted - a game underwater! TaDa - there you have it, my millionaire pound (dollar if you're the other side of the pond) game. No story, no graphics, and no idea on how!

So, go with me on this - my game is going to be an underwater game, where you swim around. That's it for now!!!!! Trust me, for me that's a monumental leap and no doubt my vision will grow in size as my confidence does (says a lot about how confident I am now, doesn't it!).

Ok - so at this point I've installed Torque (or TGE as I'll call my new baby), run the Starter FPS demo and got my idea to create a swimming-around-game.

Onwards and upwards.....

PS. I really hope people comment on what I'm doing wrong, how I could do it better, how I can do what I want, etc, etc. All other newbies are welcome to come by and join my love-hate relationship with Torque!!! (again, no criticism of Torque, it's brilliant I think, the love-hate relationship is with my patience and ability!!). What will be helpful, will be the comments I receive here, and on the blog. Either way, all useful tips I use (which will probably be all of them...) will be reproduced as I describe my now doubt eventful path towards Torque nirvana.....

#1
09/14/2007 (9:45 am)
A few tips for later:

If you ever get to the point you want to make source changes or recompile TGE, you may find that setting up Express to compile TGE is kindof a pain. I highly reccomend the full version of MS Visual Studio.

Once you get more heavily into scripts I highly reccomend getting Torsion. The ability to set breakpoints and step through your script code makes debugging so much easier (and less like wild gussing and massive echoing).
#2
09/14/2007 (10:13 am)
Blimey - a tip already - thanks James!!!

As it happens, I use the full version of Visual Studio at work (but not for C++, still scared by that...), and so may take that path! I doubt many can afford the second mortgage required for personal use, but a good tip and so watch this space! Torsion? Hmm.. not heard about that one, so add that to my list entitled "Things I must check out about Torque, before I get so far that you'll hear me cry, Why The Hell Didn't I Check It Out Earlier!!!". Wild guessing and massive echoing...... sounds familiar already, and I havn't even managed to do an echo yet! (What does that do? Just output to the screen, or somewhere else I wonder....)

Worth mentioning a link I found which takes you through installing Visual Studio C++ 2005 Express (getting ahead of myself, I'll come back to this later, but kinda in context!). Go to this article for a great, and worked first time, article.
#3
09/14/2007 (11:02 am)
Torsion is the official TorqueScript editor, available for purchase at the GG store. I just happen to work at SickheadGames, the creators of Torsion '-)

Also,

echo("bla"); // prints bla to the console
#4
09/14/2007 (11:29 am)
Ok - will check that out, as I'd like to see what tools are around - and nothing wrong with a shameful plug, lol! Now you're getting ahead of me already, where on earth would I put
echo("bla");
don't even know which file to open! (have obviously ordered every book with the word Torque in it....)
#5
09/14/2007 (11:31 am)
Okay - after running around killing that bloody orc (or not, actually killing him, more like not killing him), I went through the tutorial mentioned in the previous post, and was happily running around my terrain.

So after the tutorial I can happily make hills and valleys, paint them, and although I'm sure the novelty will wear off, it's pretty cool isn't it?!

But picking up logo's is not going to make much for my swimming around game, so I copied all the original tutorial.base files back again (deleting actually and starting from scratch). I'm now happily convinced I can crack on with my game.

With a brand new and empty world, I have my mission area covered in blue and red checkerboard. So water - I'm going to need quite a lot of it really, after all hard to swim without a little H2O!

I hunted high and low the other night (and early morning), clearly missing where I should go, to find how to add water. A bottle of wine, a long evening, and some really helpful replies on the forum and I did it!

Wahoo!

What I needed was a Waterblock as it turns out, and I can add that in the World Creator. So into my mission I go, hit F11, and go to World Editor Creator (press F4). I'm ready to add my waterblock. To do this, expand in the right hand side, the Mission Objects bit (next to the plus sign), followed by Enviornment and in there is a list of what I'm sure I'll get to know well, including..... Water! Get in!

Click on Water and you get a dialog box - I just accepted the defaults. A square of sorts might appear in the main window depending on your terrain, and in the top right window a Waterblock has appeared (you may need to expand the top folder if you havn't already). It's got a blue drop (I think it's a blue drop anyways) next to it.

But not great yet, and what follows is a summary of a fair amount of surfing the web, reading forums, getting it wrong, and generally losing a lot of hair and sleep. So enjoy, it's yours for free..... ;)

Flick over to the World Editor Inspector (F3) and click on the water block - the bottom right panel shows the "properties" of the water block.

Change the settings as follows:

Under TRANSFORM:
Position: -1024 -1024 0 (this will put one corner in the far corner of your mission)
Rotation: 1 0 0 0 (I guess, don't rotate)
Scale: 2048 2048 100 (The first two stretch it out over the whole area - like a blanket, the third is height - how high it is)

Under DEBUGGING:
I left this checked, looks better, not sure what it's for at the mo!!

Under MEDIA:
You can browse for a water texture here (first one), shore texture (second one) and other things. For now, they are all blank apart from the last which is set to specmask.jpg. I found my various water textures by looking around the folders that came with Torque and copying the all into the folder called water under your game directory - under the data folder. If you're wondering, I've got water texture set to water.jpg (or one of them, there are two floating around - floating? get it? sigh), and shore set to water_spec.jpg (I just like the way that one looks).

Under FLUID:
I've set it to Ocean Water, density of 1 and viscosity of 10

Under SURFACE:
Not really sure what this lot does yet, but was happy with the following settings:
1, 0.75, 0.2, 20, 30, 0.2

Under MOVEMENT:
Again not really sure what these do yet, but set them as:
240, 0.05, 0.1, 0.02, 0.8

Under DEPTH FX:
These are set to 6, 1, 0.1, 1

Under MISC:
tile: unchecked
AudioEnv: nothing
removeWetE: nothing
Speculur color: 0, 0.1, 0.2, 1
Speculur power: 20
Dynamic fields: I deleted all of them EXCEPT envMapTexture, which is set to ~/data/skies/sunset_0007.jpg (don't ask me what it does.... but these settings give me what I want, especially after adding the swimming bit, so go with me if you're following what I'm doing!!!)

Now after applying these and looking around I've got a pretty large puddle - you have no idea how pleased I was. Not quite up their with the birth of my children, or Ipswich getting promoted to the Premiership (I know we're not there any more), but it's not far off.... (oh, Premiership is the top league in England, if you're not in England, oh and that's football - or soccer as David Beckham is being asked to call it now.....!).

Now bring the puddle up to something that can be more seriously considered a lake was just a matter of clicking on the "Z" in the main window and dragging it up - sweet! Looking at the position value it's now -1024 -1024 35, so guess that'll do for now! The water I chose is a nice bright rippling blue and the shoreline has a whiteness to it - lovely!

Right, I now have something to swim in, but when I run into the water, I stick to the bottom like a heavy thing - actually, a bit like an orc in armour... And when I jump, I land straight back down on the bottom. I want to swim, which means no gravity in water basically. And of course, gravity must still work on the surface, so I can't just get rid of gravity totally.

Getting swimming to work reasonably was another long and windy road.... see the next article, and be prepared to roll up your sleeves - it's a beut....!!! If I was still married, it would have led to divorce I think.
#6
09/14/2007 (2:20 pm)
Ok --- this is the big one. I've painted terrain, made a lake and even filled it with water! Very pleased with myself, pat on the back and all that. But now, getting my player to swim would be the next step.

I had it in the back of my mind that it would just be a parameter somewhere, but -- oh no -- this was not to be! Quickly I realised that this was going to involve some pain.

So, as this is past tense, you'll be pleased that I can bring you the fruits of my labour (well, fruits of countless searches on Google and the GG forums at least). As these ramblings become present tense, expect much more uncertainty and drrrrunken useless information....

So what follows is my pick of what was on offer - it is simple, quick to do, and it just worked first time. Three massive ticks in three fairly gigantic tick boxes in my life.

I needed to install Visual Studio C++ 2005 Express Edition (or take those words and move them around to get the correct title). Go to here for a super duper step through on how to download and install - key answer to your next question, yes, it's free :)

Having got to the point of running VS2005 (my shorthand for the above...) and opening the Torque SDK project, I had to edit and re-compile the Torque Game Engine. Altogether now.... GULP!

So yes, I went ahead and opened up the Source Files folder, then the game folder. In there is a file called player.cc --- I confidently opened this up by double clicking it....

I searched for void Player::update as instructed to (could have used the drop down list towards the top-right of the window - when you drop the list, a whole load of - fairly meaningless - functions and so on are listed!!!).

Now in this function, I scrolled down to where it says:

// Acceleration on run surface
if (runSurface)
{

which is part of the code which is saying "if running on surface we're going to have to do some sort of acceleration". Now before it says

}
else
mContactTimer++;

I had to insert some code. So, it looks like this at the moment:

// Acceleration on run surface  

if (runSurface) { 
      bla bla bla ---- code already here,  

      lots of lines of code  

      and so on.....
} 
else  

    mContactTimer++;

But will look like this:

// Acceleration on run surface  
if (runSurface) { 

      bla bla bla ---- code already here,  
      lots of lines of code  
      and so on.....
}  
else if (inLiquid)  
{    
      more code here which you're going to put in!!!
}

else  
    mContactTimer++;

I hope that is a simple explanation of that bit of code, because what follows is the bit I replaced "more code here which you're going to put in!!!" with (see above code snippet!). So I went ahead, put in the above if ... else if ... else construct is in place, and then made it look like the following:

// Acceleration on run surface
   if (runSurface) {
 
      **** ignore what code is here, it's the bit below which is important ****

   }
   else if (inLiquid)
   {
		// get the head pitch and add it to the moveVec
		VectorF swimVec(0,0,-mHead.x);
		moveVec += swimVec * move->y;

		// Force a 0 move if there is no energy, and only drain
		// move energy if we're moving.
		VectorF pv;
		if (mEnergy >= mDataBlock->minRunEnergy) {
		if (moveSpeed)
		mEnergy -= mDataBlock->runEnergyDrain;
		pv = moveVec;
		}
		else
		pv.set(0,0,0);

		F32 pvl = pv.len();

		// Convert to acceleration
		if (pvl)
		pv *= moveSpeed / pvl;
		VectorF runAcc = pv - mVelocity;
		F32 runSpeed = runAcc.len();

		// Clamp acceleration, player also accelerates faster when
		// in his hard landing recover state.
		F32 maxAcc = (mDataBlock->runForce / mMass) * TickSec;
		if (mState == RecoverState)
		maxAcc *= mDataBlock->recoverRunForceScale;
		if (runSpeed > maxAcc)
		runAcc *= maxAcc / runSpeed;
		acc += runAcc;

		mContactTimer++;
   }
   else
      mContactTimer++;


God I hope that makes more sense to you than it did to me first time around!

I re-compiled the Torque .exe file again, from the Build menu - the page that described downloading and installing VS2005 Express covered that too. Note here: if you do this make sure that you use your new .exe file to run your game now, with the changes included - not the previous one!!! (yes, I did for a while, hence I pass on this nugget of wisdom....)

I never thought I'd be re-compiling the TGE file so quickly, kinda hoping it's not something I do regularly - but I suspect if I do get into TGE big time I certainly will be!!! Happy coding ahead me thinks....

So, am I happy or what?! :) With this I can now swim without sinking. Pretty cool, my swimming type game is coming across leaps and bounds!!!

Important note bit: you may need to jump off the bottom of the lake if you've just walked into it to launch yourself up.

Very chuffed with myself :) But please, if you see a problem, or a better way, or a suggestion, PLEASE say so, I'm here to learn!!!
#7
09/14/2007 (2:34 pm)
I do want to point out that you've saved the hardest part until last...not in any way trying to shut you down or demotivate you, but you've done the easy stuff--getting realistic swimming has quite a bit of work behind it, and strong understanding of quite a bit of the engine.

Just bite down and bear the learning process, and you'll succeed, but be aware you've got your work cut out for you.
#8
09/14/2007 (2:49 pm)
LOL - not demotivated at all - my expectations are quite low at the moment. I've decided to do a SCUBA simulation game, and realise that my "swimming" is not the most realistic at the moment, but for now it allows me to avoid plumetting to the floor of the water, and instead float/swim(ish)/move around! Funniest faux pas at the moment is that my "player" underwater is an Orc standing vertically.... So sticking to first person view at the moment, hehe.

I'm currently standing at the bottom of a long and high and steep learning curve!

To be a useful diving simulation I now need to have a heading (in degrees) on the GUI. "Your heading is: 210 degrees" - that sort of thing. I've posted elsewhere and I think many assumptions about what and how to do it may well be wrong. The forum, for the record, has been a SUPERB resource and help.

Hopefully the path I've trodden will be of help to others starting Torque, and when not appropriate can be safely ignored! Like the swimming..... And other parts, like updating the GUI in general terms, will be of help!

Thanks Stephen - appreciate your post.
#9
09/14/2007 (2:53 pm)
For heading, I'd take the dot product of a "north" vector, and the player's heading or muzzle-vector. arccos that, and you will have the heading in radians, convert to degrees and you should be good to go.
#10
09/14/2007 (3:21 pm)
Blimey Pat - wow - that sounds fantasic, just need to translate that into English, hehe! No, seriously, thanks. My first task is to be able to update some text on the GUI, which I'm now attempting....! Will no doubt return to your advice after, hehe.

So, to update the GUI I added a GuiTextControl via the GUI Editor (F10), named it guiTest (imaginative eh?).

Now, in server/scripts/player.cs at the top I've added the following (not even sure it's the right place to put it). The idea is that it will constantly calculate the heading and update a control on the GUI.

guiTest.setText("HERE");  // This works, so I know it's calling this code  
%this.schedule(100, 0, "updateHeading");

function updateHeading(%this)
{
     %heading = 90; // Hard coded for testing purposes
     guiTest.setText("Heading:" @ %heading);  //guiTest is the name of the GUI control
     %this.schedule(100, 0, "updateHeading");   // set another schedule straight away for this function
}

But, it doesn't work.... and that's where I'm at right now!! And, of course, any and all help appreciated!!!

Quick update, I tried the following and it doesn't put "UPDATED TEXT" on the GUI control, so don't even think the functions are being called correctly (this is at the top of server/scripts/player.cs). Gosh, I have a long way to go (sigh):

testGUI(%this);

function testGUI(%this)
{
     guiTest.setText("UPDATED HERE");
}
#11
09/14/2007 (3:27 pm)
This is one of the areas that needs a lot more study :)

You placed the code in the /server directory, but GUI (and all other object) rendering is performed client side. This will work in a single player game, but is very bad programming practice--you'll need to network the heading information down to the client, as either a net event (commandToServer and clientCmdXXX), or ghost the information as part of the player object itself.

Also, we don't have a reference of code around your "%this.schedule(100, 0, "updateHeading"); but I can tell you right now it's the wrong syntax--you are using the global schedule function parameter order while making an object namespace schedule.

While it will "work", it's not good programming practice (for the reasons I mention above), but change your schedule line to this:

schedule(100, guiTest, updateHeading);
#12
09/14/2007 (3:39 pm)
Thanks Stephen, going back to the books and reviewing some chapters now I think. I've ordered both the "All in One Book" (I've got the advanced, but lost my old copy of the first book, hence the re-order!) and the "Game Programmers Guide to Torque" - I'm hoping one or both cover this area? Any pointers to which is the better book for such problems as my heading display...? Thanks....
#13
09/14/2007 (3:46 pm)
They are both good books, and I can't really recommend one over the other--in fact, if budget allows, I'd get both simply for the spread coverage.
#14
09/18/2007 (3:52 pm)
This is an awesome thread and awesome resource!
#15
09/18/2007 (11:54 pm)
Thanks - I've ordered my two books (GPGTT and AIOB1), both from America I think, so bitting nails patiently until they arrive......
#16
09/20/2007 (2:43 am)
Okay - this may not be what most people would do, but I've decided to get help with my project, rather than spend the next 50 years or so learning, what others can provide in a matter of days, for a modest fee. So, if others are looking to involve others, building a team, then this may prove to be useful (especially if things go bad, as you can learn from my experience first!!!). Hopefully, my new team will be the bees-knees :)

So, I've posted on the Marketplace forum, and placed a Job Ad. They pretty much ask for the same thing, check it out here.

Almost straight away, I was contacted via the post, by a developer in the US, and one in Australia. I'm in the UK - but not a problem, small world now! I also found an excellent graphic designer, based in the UK, via the forums, and have contacted him.

The rates are reasonable, with quotes that I would consider to be a great investment. I have selected the Australian guy (will keep things anonymous) as he has samples of existing work that is very close to what I am after.

I am still waiting to hear rates from the graphic designer for the creation of landmarks. We'll have to see, I'm a bit scared about this one, as the effort involved is high, and therefore cost will probably match. Eeek.

I'll let you know how I get on with using a developer the other side of the world! I'm hoping it works out well, as he has a colleague who can do player characters, which I will need. You don't see too many Orcs swimming around the seas anymore....
#17
10/02/2007 (2:08 pm)
Thought I'd update this thread with my TGE experience so far..... Well, for the compass I've spent $200 and consider it money well spent. Ashley - the programmer I'm using from down under Aussie way, has been brilliant and I now have a dive computer - which look like a chunky watch that shows heading in degrees, depth from the water surface, and even a rotating direction compass showing North. Very happy, and I would have taken months (and probably given up). If I work out the hourly rate Ashely has been working at I'm rather embarrased!! As an overview it ended up as a new GUI control, so really easy to add to any GUI. All I have to do is drop a couple of files into Visual C++, re-compile and change settings in customProfiles.cs - I've even started tinkering with the code to reposition some elements of the GUI control.

I'm now back to specifying swimming and will get Ashley to program that in, but still deciding exactly how that will work as it will cost me more. However, when compared to the value of my time, the money I'm spending is considered very worthwhile - very cost effective investment in the product.

As for the Graphic designer, well read on about my experience of Studio Max 9, Constructor and creating DTS's.
#18
10/02/2007 (2:09 pm)
Oh, as an aside my copy of GPGTT has arrived and I like the style and level of it.
#19
10/02/2007 (2:26 pm)
Right then --- graphics.....!!!! For my end product I need a lot of underwater design - both terrain, environment (rocks, etc), and objects such as wrecks. Oh, and tunnels.

Now an awful lot of forum reading later, it's clear that what I SHOULD be doing is creating DIFs for my bigger stuff (buildings above the surface, wrecks that I can go inside, and so on), and DTSs for the smaller detailed stuff.

However..... I spent a day watching video tutorial after video tutorial (at www.lynda.com - very good) for 3D Studio Max 9 which I'm fortunate enough to own a copy of. It's BRIIIIIILIANT!!!!! I love it, want a career change! So I've gone way, way down this route. I then learned (too late really), that 3DS Max cannot produce brushes (that's DIFs, hey I'm picking this up, hehe). I would have to use something else.

So, undeterred, I tried Quark and Constructor. Quark is just out of the arc, a clunky bloody thing if you ask me (apologies to any Quark lovers, sorry!). Constructor felt better, and I'm sure would be my choice, congrats to GG for producing a free product of such quality. To all those who have posted moans about Constructor, one message: get over it!!! Get it the mood - if you're going to produce games you gotta be able to take the rough with the smooth and work with it.... rant over!

Anyway, back to me (!). My biggest problem is once you've had the best, it's hard to cope with other things. No judgement on Constructor, but 3ds Max just gets your juices flowing - it's just so nice to just use it! So I've spent a lot of time going against the general advice and tried to get a DTS exporter working for Max 9 so I can build as much as possible (I know, I hear you) in Max 9.

This means a lot of DTSs that should be DIFs, but I won't have loads and loads. And 3ds Max produces such lurvly results, I want them! So there! And you are completely entitled to go yah boo sucks to me, when I post a U turn and change my mind about using DIFs not DTSs (just need a nicer way to make them).

The exporter for Max 9 was a pain, but is great now (must of the time) - stick with it! I will link to the versions I used as a lot of people post asking when I can find them, but it was a ZIP file for (I think) an older version (7 or 8 I think), the includes scripts, images, and so on, and a .dle file that is out of date. I think downloaded a version for 9 that I put in the stdplugins folder. Sorry, but I tried every combination and have a load of ZIP files on my desktop!!! I think I should be able to re-create the ZIP file - add a post here if you want me to.

When exporting, to get the collision mesh to work, it should be a *copy* of your object. That way you can still go through it. I get problems with more complicated objects, so got a way to go, but making good progress.

Oh, and I've managed to get rid of the crossbow by un-mounting, and disabled TAB so it's first person only for the time being. Both achieved by editing scripts, help found by simply searching the forums. They're the bees-knees for answers!!
#20
10/07/2007 (3:03 am)
Things are coming along nicely now in some respects, and nightmare in others - I've got underwater visibility sorted with a fog layer - cool, but it's caused some real problems in how my shapes or interiors are displaying.

The settings for my fog layer are:

fogStorm1 = "0";
      fogStorm2 = "1";
      fogStorm3 = "1";
      fogVolume1 = "30 0 138";
      fogVolume2 = "0 0 0";
      fogVolume3 = "0 0 0";
      fogVolumeColor1 = "128 128 128 -2.22768e+038";
      fogVolumeColor2 = "128 128 128 0";
      fogVolumeColor3 = "128 128 128 -1.70699e+038";

My water level is 138 which matches the fog level. fogVolume1 sets the underwater fog: 30 is visibility distance, 0 is the bottom and 138 the top.

But......

Big DIFs don't fade into the fog, and DTS shapes "pop" into view when not in the fog. The later is fine for small objects as the "pop" in when in the fog, and then get clear as you get close.

But it's a nightmare for big DTS files (so yes, I should be using DIFs....), but the DIFs don't fade and it looks awful - the fog just doesn't seem to be working.

Anybody help? I've posted the problem on a seperate thread here.