Game Development Community

Fish Tutorial Controls Not Working

by Dylan Duarte · in Technical Issues · 08/06/2008 (11:56 pm) · 3 replies

I just downloaded the trail version of Torque Game Builder and I'm in the middle of the Fish tutorial, specifically at the part where you add the keyboard controls to control your fish. I created a cs file with the code and the Fish Tutorial Controls behaviors shows up the in list. I select it, assign, and input all of my control keys. However, when I go to test it, they don't work. I can't get the fish to move at all. I've tried several different keys. I've restarted the game and re-copied the code.

Any ideas?

Thanks in advance.

About the author

Recent Threads


#1
08/07/2008 (1:54 am)
So I got the move script working by pasting the code into dreamweaver and meticulously going through all of it and manually formatting it to look the same, instead of just being a block of text, which is how it looks when you paste it in there.

Is there any way to copy the code from the tutorials and keep the formatting?
#2
08/07/2008 (2:19 am)
So it randomly stopped working and I'm back where I started. Suggestions?
#3
09/18/2009 (2:06 pm)
I don't know,
but I am exactly where you were circa 08. I have just popped this in as these controls will be ideal for me right now, but nothing. Any suggestions?


if(!isObject(fishControlsBehavior))
{  
   %template = new BehaviorTemplate(fishControlsBehavior);
   %template.friendlyName = "Fish Tutorial Controls";
   %template.behaviorType = "Input";
   %template.description  = "Movement control for our Fish Tutorial";
   %template.addBehaviorField(upKey, "Key to bind to upward movement", keybind, "Up");
   %template.addBehaviorField(downKey, "Key to bind to downward movement", keybind, "Down");
   %template.addBehaviorField(leftKey, "Key to bind to left movement", keybind, "Left");
   %template.addBehaviorField(rightKey, "Key to bind to right movement", keybind, "Right");
   %template.addBehaviorField(verticalSpeed, "Speed when moving vertically", float, 15.0);
   %template.addBehaviorField(horizontalSpeed, "Speed when moving horizontally", float, 30.0);
}
function fishControlsBehavior::onBehaviorAdd(%this)
{  
   if (!isObject(moveMap))
      return;     
  
   // bind our keys on the keyboard  
   moveMap.bindObj(getWord(%this.upKey, 0), getWord(%this.upKey, 1), "moveUp", %this);
   moveMap.bindObj(getWord(%this.downKey, 0), getWord(%this.downKey, 1), "moveDown", %this);
   moveMap.bindObj(getWord(%this.leftKey, 0), getWord(%this.leftKey, 1), "moveLeft", %this);
   moveMap.bindObj(getWord(%this.rightKey, 0), getWord(%this.rightKey, 1), "moveRight", %this);
   %this.up = 0;   %this.down = 0;   %this.left = 0;   %this.right = 0;
}

function fishControlsBehavior::moveUp(%this, %val)
{  
   %this.up = %val;
   %this.updateMovement();
}

function fishControlsBehavior::moveDown(%this, %val)
{  
   %this.down = %val;
   %this.updateMovement();
}

function fishControlsBehavior::moveLeft(%this, %val)
{  
   %this.left = %val;
   %this.updateMovement();
}

function fishControlsBehavior::moveRight(%this, %val)
{  
   %this.right = %val;  
   %this.updateMovement();
}

function fishControlsBehavior::updateMovement(%this)
{  
   // figure out what speed in what direction we are moving based on key input  
   %this.owner.setLinearVelocityX((%this.right - %this.left) * %this.horizontalSpeed);  
   %this.owner.setLinearVelocityY((%this.down - %this.up) * %this.verticalSpeed);     
 
}