Game Development Community

Basic movement with TGB ninja demo tutorial

by Christopher ross · in Torque Game Builder · 10/15/2007 (10:29 am) · 11 replies

Great tutorial but couldnt get arrow keys to affect movement and jump was once then crash cant believe it took me so long to figure out i needed to put this at the end of the player.cs


// cant believe this took me so long to spot and fix

function PlatformerSceneGraph::onUpdateScene()
{
if (isObject($pGuy))
$pGuy.updateMovement();
}

// and rename scenegraph in tgb edit scene object name = PlatformerSceneGraph


Full player.cs below
=======================================================

so my player.cs looks like this now
function playerClass::onLevelLoaded(%this, %scenegraph)
{
$pGuy = %this;

moveMap.bindCmd(keyboard, "left", "playerLeft();", "playerLeftStop();");
moveMap.bindCmd(keyboard, "right", "playerRight();", "playerRightStop();");
moveMap.bindCmd(keyboard, "space", "playerJump();", "");
}

function playerLeft()
{
$pGuy.moveLeft = true;
}

function playerLeftStop()
{
$pGuy.moveLeft = false;
}

function playerRight()
{
$pGuy.moveRight = true;
}

function playerRightStop()
{
$pGuy.moveRight = false;
}



function playerClass::updateHorizontal(%this)
{
if(%this.moveLeft)
{
%this.setLinearVelocityX(-60);
}

if(%this.moveRight)
{
%this.setLinearVelocityX(60);
}

// if(!%this.moveLeft && !%this.moveRight)
// {
// %this.setLinearVelocityX(0);
// }
}

function playerClass::updateVertical(%this)
{
%yVelocity = %this.getLinearVelocityY();

if(%this.airborne)
{
%this.setLinearVelocityY(0);
%collision = %this.castCollision(0.005);

if(%collision !$= "")
%this.setLinearVelocityX(0);
}

%this.setLinearVelocityY(100);
%collision = %this.castCollision(0.005);

if(%collision $= "")
{
%this.airborne = true;
%this.setConstantForceY(100);
}
else if(%yVelocity < 0 && %this.airborne)
{
%this.setConstantForceY(100);
}
else
{
%this.airborne = false;
%this.setConstantForceY(0);
}

%this.airborne = false;
%this.setLinearVelocityY(%yVelocity);
}


function playerClass::updateMovement(%this)
{
%this.updateHorizontal();

%this.updateVertical();

}

//function playerJump()
//{
// if(!$pGuy.airborne)
// {
// $pGuy.setLinearVelocityY(-225);
// $pGuy.airborne = true;
// }
//}


// cant believe this took me so long to spot and fix

function PlatformerSceneGraph::onUpdateScene()
{
if (isObject($pGuy))
$pGuy.updateMovement();
}

// if this saves someone else a few hours cool

#1
10/15/2007 (12:32 pm)
Yeah, the big problem with those tut's are that alot of them are out of date and don't reflect recent changes.
I thought about cleaning that one up a bit and just might if I ever get the time
#2
10/23/2007 (4:56 am)
Need I really add another comment about this.. .How can GG (or the community) provide tutorials but not support them and keep them up to date with product updates? That's like releasing documentation and then not updating it for the next release.. oh.. yeah..

I really wish there was some person hired to do nothing else but work on tutorials/web videos/video tutorials and documentation at GG. It's something every company should have.. espeically one that caters to Indie/new/hobby programmers. IMO
#3
10/23/2007 (1:45 pm)
I dunno. I learn a lot about the engine by finding the workarounds for the errors or out-of-date parts in the tuts and other documentation. Okay, so it's frustrating to run into a non-working part of the tut, but I view it as a learning experience. There are usually enough clues in the (tut + script + source code) for even a newbie to figure it out.

If I were a better Torque citizen, I would edit the erroneous parts of the tuts and other documentation after I have found them and fixed them. It is, after all, a user-editable Wiki.
#4
10/23/2007 (2:50 pm)
Keep in mind TDN is a user maintained documentation hub, we've contributed to it in the past but we've always tried to be clear that we aren't maintaining it ourselves. So many of the docs on TDN are out of date though they are not official docs.

As far as out of date material in the release, unfortunately with the latest release various out of date material was presented, though fortunately a lot of it was caught and changed so it is fairly minimal. Feel free to report the problems in the bug report area and they will be logged for future releases.

We do in fact have people who contribute to docs, for quite a while about 90% of my time was just docs, which is why 1.1.3 of TGB had a very solid doc base. Unfortunately for 1.5 some of those slipped through our fingers of being updated though it's still a fairly solid doc base. Sure there could be more, but don't underestimate the time and resources it takes to develop docs. Often people consider it easy, when it's far from. It also takes a good deal of time to maintain docs, especially as many as the TGB official docs. Right now if we were to try and maintain TDN and user created docs that would be a huge resource sink. Also considering those were done by community members it doesn't make sense for GG to go update all of them.

We are focusing on documentation more in the future and we are getting there. For a comparison of how far we've come look at TGB compared to what comes with TGE. We've come quite a long way.

I still feel we offer a solid doc base in TGB and though not 100% complete I still find it fairly complete relative to other products like it. Again this doesn't mean we aren't working on this for the future.

Video tutorials are a very good learning tool, but have a very high upkeep cost. It takes quite a deal more resource to just update text & image tutorials than most people think, but a video tutorial takes quite a bit more. It seems like a trivial thing, but as someone whose worked on TGB docs for 1 1/2 years + I can assure you it is far from trivial :)

When I picked up T2D (before it's name was changed to TGB) there was one tutorial, various other people in the community were around then as well. There were no tools at all. I managed to learn a great deal about TGB then and put out 10 of my own tutorials before coming to GG. If I (and others) can do it I know others can. That is not an excuse away from creating more documentation and better documentation, simply a realization that people often limit themselves unfairly.

I created a Documentation suggestion thread, feel free to contribute to that if you want to be productive and want to see your input taken in a useful manner.
#5
11/19/2007 (10:32 am)
K a working demo (scoreboard doesnt work atm) of ninja1 is available at www.darksprite.co.uk/ninja1.zip

I'd just like to raise a few issues:

1. There needs to be more work on making the executable as stable as possible, amongst all flavours of windows xp / vista. When i run this game on my main work computer it just crashes, when i run it on another computer it works ok when i run it at home its fine. When i dl to a mates old laptop windows xp v1 the ninja main sprite dissapears, this kind of nonsense just isnt acceptable for a professional game.
Why dont I just use flash for 2d game making i keep asking myself.

2. This issue about documentation is quite a big one. Someone needs to be paid to put the documentation in order and create new good resources. The tutorials are a great start and obviously a lot of time and effort went into them. However, I am not that interested in tinkering about with code to get nowhere, the idea behind the game builder is the ability to knock out games fast. A Rapid Application Development tool, more resources need to be put into making step by step tutorials THAT WORK with the latest release to get the job done. Platformers need a scoreboard, a next level, sound, enemies, powerups, coins. Trying to do all this with tutorials that are broken isnt much fun at all.

3. Having to login 3 times to make a contribution isnt that cool.

4. The reason for switching to TGB was that TGE was getting heavy going for basic game design functionality and stability issues.

The more I think about it the more it makes sense to develop basic 2d games in flash, which offers true cross platform and internet live games, has better documentation, and a bigger better knowledge and user base.


If anyone can help making a working scoreboard that would be cool.

Prove me wrong garage games :)
#6
11/20/2007 (12:42 pm)
Hi, just started up with trial TGB 1.5.1 on a MacBook Pro 10.4.11..I am a beginner in programming so I started with the Fish stuff..have to say that it is quite fun so far! Installation worked, only some links in the HTML documentation are broken due to some minor mistakes in path names (like using \ instead of /). Apart from this the demos and the sample script code were a great experience, did not have problems at all. Only the checkers game is hard as you need 2 computers in a network and the code is tricky. I tried to use JEdit for Mac but it didn't work..the installation is described in the readme but it is quite confusing. So debugging with TextEdit is good for the start but later on it will be a problem to be solved.
Coding is hard for beginners, but you get used to it. What I still have not found is a documentation of Torque Script syntax..I am still surprised about new functions 'arising' out of nothing in more advanced scripts in the tuts.
As a newbie to programming I need to start from scratch..I don't want to copy code to make my games, I want to write it myself to understand what I am doing. But I am sure that I will find the specs soon.
So far cool stuff GG!

BTW: boot camp seminars for 3000 dollars? rethink it!
#7
11/21/2007 (8:33 am)
The TGB ones are $299 a seat for an in-depth 2-day training bout.
#8
11/26/2007 (11:05 am)
Yeah i think a boot camp may well be in order very soon
#9
12/18/2007 (4:14 pm)
Do you have a working version of the platformer demo? Your link is broken. I tried recreating the demo from scratch using your movement code but it doesnt work.
#10
10/17/2008 (9:59 pm)
a
#11
11/26/2008 (6:50 am)
Use the updated tutorial, it works. But then you'll get the problem with the game not updating the animations. The platformer start kit does look nice but I don't really want to make a platformer game, just messing around.