More Movement Problems
by Meh... · in Torque Game Builder · 10/15/2006 (7:34 pm) · 8 replies
Hey everyone, now that a couple of things worked for me, a lot more had to go wrong to balance it out. I'm in the fish tutorial 4.4, where it helps me clean up movement. I put in everything it says. Then when I run the game, my fish moves exactly the same, there is also an error in line 3 of my code, though I have no idea what it is. Here's a script sample.
Thanks, I'd appreciate any help.
function Playerfish::onLevelLoaded(%this, %scenegraph)
function PlayerFish::updateMovement(%this)
{
if(%this.moveLeft)
{
$FishPlayer.setFlipX(false);
$FishPlayer.setLinearVelocityX( -$FishPlayer.hSpeed );
}
if(%this.moveRight)
{
$FishPlayer.setFlipX(true);
$FishPlayer.setLinearVelocityX( $FishPlayer.hSpeed );
}
if(%this.moveUp)
{
%this.setLinearVelocityY( -$FishPlayer.vSpeed );
}
if(%this.moveDown)
{
%this.setLinearVelocityY( $FishPlayer.vSpeed );
}
if(!%this.moveLeft && !%this.moveRight)
{
%this.setLinearVelocityX( 0 );
}
if(!%this.moveUp && !%this.moveDown)
{
%this.setLinearVelocityY( 0 );
}
}
{
$FishPlayer=%this;
moveMap.bindCmd(keyboard,"w","fishPlayerUp();","fishPlayerUpStop();");
moveMap.bindCmd(keyboard,"s","fishPlayerDown();","fishPlayerDownStop();");
moveMap.bindCmd(keyboard,"a","fishPlayerLeft();","fishPlayerLeftStop();");
moveMap.bindCmd(keyboard,"d","fishPlayerRight();","fishPlayerRightStop();");
moveMap.bindCmd(keyboard,"space","fishPlayerBoost();","fishPlayerBoostStop();");
}
function fishPlayerUp()
{
$FishPlayer.moveUp = true;
$FishPlayer.updateMovement();
}
function fishPlayerDown()
{
$FishPlayer.moveDown = true;
$FishPlayer.updateMovement();
}
function fishPlayerLeft()
{
$FishPlayer.moveLeft = true;
$FishPlayer.updateMovement();
}
function fishPlayerRight()
{
$FishPlayer.moveRight = true;
$FishPlayer.updateMovement();
}
function fishPlayerUpStop()
{
$FishPlayer.moveUp = false;
$FishPlayer.updateMovement();
}
function fishPlayerDownStop()
{
$FishPlayer.moveDown = false;
$FishPlayer.updateMovement();
} function fishPlayerLeftStop()
{
$FishPlayer.moveLeft = false;
$FishPlayer.updateMovement();
}
function fishPlayerRightStop()
{
$FishPlayer.moveRight = false;
$FishPlayer.updateMovement();
}
function fishPlayerBoost()
{
%flipX = $FishPlayer.getFlipX();
if(%flipX)
{
%hSpeed = $FishPlayer.hSpeed * 3;
} else
{
%hSpeed = -$FishPlayer.hSpeed * 3;
}
$FishPlayer.setLinearVelocityX(%hSpeed);
}
function fishPlayerBoostStop()
{
$FishPlayer.setLinearVelocityX(0);
}Thanks, I'd appreciate any help.
About the author
#2
10/15/2006 (9:00 pm)
Sorry, but where (and what?) is the private form?
#3
10/15/2006 (10:14 pm)
I've lost track of what's acceptable and what's not, as far as posting code publicly, but right off the bat, you have a missing open brace after the first function declaration.
#4
So,
Like that maybe?
10/15/2006 (10:28 pm)
Sorry, maybe an example? Remember guys, I'm a BIG script newbie. Open Brace; like this; {So,
function Playerfish::onLevelLoaded(%this, %scenegraph)
{Like that maybe?
#5
You can never ha ve a function in a function in code/script :)
change the first part to this:
10/20/2006 (6:01 pm)
It looks like your wrapping functions with in a function... You can never ha ve a function in a function in code/script :)
change the first part to this:
function Playerfish::onLevelLoaded(%this, %scenegraph)
{
$FishPlayer=%this;
moveMap.bindCmd(keyboard,"w","fishPlayerUp();","fishPlayerUpStop();");
moveMap.bindCmd(keyboard,"s","fishPlayerDown();","fishPlayerDownStop();");
moveMap.bindCmd(keyboard,"a","fishPlayerLeft();","fishPlayerLeftStop();");
moveMap.bindCmd(keyboard,"d","fishPlayerRight();","fishPlayerRightStop();");
moveMap.bindCmd(keyboard,"space","fishPlayerBoost();","fishPlayerBoostStop();");
}
function PlayerFish::updateMovement(%this)
{
if(%this.moveLeft)
{
$FishPlayer.setFlipX(false);
$FishPlayer.setLinearVelocityX( -$FishPlayer.hSpeed );
}
if(%this.moveRight)
{
$FishPlayer.setFlipX(true);
$FishPlayer.setLinearVelocityX( $FishPlayer.hSpeed );
}
if(%this.moveUp)
{
%this.setLinearVelocityY( -$FishPlayer.vSpeed );
}
if(%this.moveDown)
{
%this.setLinearVelocityY( $FishPlayer.vSpeed );
}
if(!%this.moveLeft && !%this.moveRight)
{
%this.setLinearVelocityX( 0 );
}
if(!%this.moveUp && !%this.moveDown)
{
%this.setLinearVelocityY( 0 );
}
}
#6
10/20/2006 (6:01 pm)
Note, indenting really helps you see errors like that
#7
10/22/2006 (11:51 am)
Since this is tutotorial code.. why would this need to be in the private (ie: exclusionary) forum?
#8
10/22/2006 (7:11 pm)
When you are doing these tutorials, examples of the proper code are available right there along with the instructions. If you are having code issues, you might want to just copy and paste the supplied code when your first swing at it doesn't work.
Torque Owner Fucifer