Game Development Community

Advanced Platformer Mechanics

by rennie moffat · in Torque Game Builder · 08/10/2009 (9:36 am) · 10 replies

So I moved on to this tut, to see if I can generate movement. After the first few steps I should be able to have a player which reacts to keyboard commands. Mine doesn't. I Have 2 question on this tho.

a. is my code alright? it was (player.cs) copy and pasted.
b. datablocks. this script contains a datablock for the player which must be put in the gametitle/main.cs. I was unsure as to how to add the script, did a bit o research but have added it (player datablock) in the onStart Function.

So here is my code, my player object, is scripted as player, playerClass. So what gives? I am not sure what might be wrong. Any help would be appreciated. Thanks in advance.




// Constants.  Tweak these, and the constant force on the player object, to
// adjust how quickly the player moves.
$xSpeed = 60;
$ySpeed = -200;

function PlayerClass::onLevelLoaded(%this, %scenegraph)
{
    $player = %this;

    moveMap.bindExclusiveCommand(keyboard, "space", %this, "%obj.playerJump();", "", "jumpDirection", "up");
    moveMap.bindExclusiveCommand(keyboard, "left", %this, "%obj.playerLeft();", "%obj.playerLeftStop();", "leftRightDirection", "left");
    moveMap.bindExclusiveCommand(keyboard, "right", %this, "%obj.playerRight();", "%obj.playerRightStop();", "leftRightDirection", "right");
     
    moveMap.push();  
}

function PlayerClass::onRemove(%this)
{
    moveMap.pop();
    $player = null;
}

function PlayerClass::playerLeft(%this)
{
  %this.setLinearVelocityX(-$xSpeed);
}

function PlayerClass::playerLeftStop(%this)
{
  %this.setLinearVelocityX(0);
}

function PlayerClass::playerRight(%this)
{
  %this.setLinearVelocityX($xSpeed);
}

function PlayerClass::playerRightStop(%this)
{
  %this.setLinearVelocityX(0);
}

function PlayerClass::playerJump(%this)
{
  if(%this.getLinearVelocityY() == 0)
    %this.setLinearVelocityY($ySpeed);
}

About the author

My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.


#1
08/10/2009 (10:31 am)
the code has some sections, that TO ME, seem to be wrong... starting with the moveMap.bindExclusiveCommand...

and, when you wanna use datablocks, they usually go in a file called "datablocks.cs" in "game/managed".
#2
08/10/2009 (11:22 am)
hmm, so are the tutorials, often not 100%, just some Wikipedia type stuff. Maybe pretty accurate but not precise exact, which is required in this industry?
#3
08/10/2009 (11:28 am)
here is a good question for you.

in this code...
function playerHeroClass::Stop(%this)  
{  
    %this.setAtRest();  
}

is my adjustment of this...
function playerClass::Stop(%this)  
{  
    %this.setAtRest();  
}



is this ok to do in a player.cs? is it necessary? relevant?




#4
08/10/2009 (11:38 am)
Quote:hmm, so are the tutorials, often not 100%, just some Wikipedia type stuff. Maybe pretty accurate but not precise exact, which is required in this industry?

What tutorial is this from?

As for this:
Quote:
here is a good question for you.

in this code...
view plainprint?
function playerHeroClass::Stop(%this)    
{    
    %this.setAtRest();    
}  

function playerHeroClass::Stop(%this)  
{  
    %this.setAtRest();  
}
is my adjustment of this...
function playerHeroClass::Stop(%this)    
{    
    %this.setAtRest();    
}  

function playerClass::Stop(%this)  
{  
    %this.setAtRest();  
}

is this ok to do in a player.cs? is it necessary? relevant?

Your adjustment is correct to get it working with your player but this would only work if you had previously written and executed some code that defined the .setAtRest() method. Most likely that would have takend place in your player.cs file.

The problem with plucking what you want form tutorials is that there are other areas of code that either are dependent, or are a dependent of, what you copy/paste. So it looks like somewhere in that tutorial they created a .setAtRest() function that you would also need to add to your project.
#5
08/10/2009 (12:48 pm)
hmm ok, well this tutorial as i said is from the Advanced Platformer Mechanics Tutorial, thus the title. But I see what you mean, it can be a bit difficult for cool guys like me, who know nothing of this to try and build a game from scratch.


It is unfortunate that they aren't totally like lego kits, but no worries, keep on.
#6
08/10/2009 (1:19 pm)
Here is a good question for you.


lI am taking from the Platformer Tutorial

http://tdn.garagegames.com/wiki/TGB/Tutorials/Platformer/



Thus far I have my playerClass.cs (copy pasted), my exec call for playerClass.cs, my object classsified appropriately. They should be enough right? or am I missing something? Not sure what else there is, but my player still does not move.
#7
08/10/2009 (2:46 pm)
usually, in the levels you build, you have to assign the playerclass to an object, for it to respond to the inputs of the player and so on...

on the question regarding to "setAtRest", thats a stock function of TGB, so you can use it with any function that pretends to stop and object within the scene, so your take onto changin the function i wrote for you, is ok.
#8
08/10/2009 (3:10 pm)
Ok so regarding class.

I named my object/player. in script, player (the name) and playerClass (the class).

That should work should it not?
#9
08/11/2009 (11:06 am)
Quote:on the question regarding to "setAtRest", thats a stock function of TGB, so you can use it with any function that pretends to stop and object within the scene, so your take onto changin the function i wrote for you, is ok.

Good to know, I can quit writing custom stop() functions now. :) Thanks!
#10
08/11/2009 (12:48 pm)
Quote:
Good to know, I can quit writing custom stop() functions now. :) Thanks!

not a problem... but i thought that function was widely known... but it seems only a handfull of ppl use it here.