About : FishGameTutorial
by M. Ugur Karakaplan · in Torque Game Builder · 01/29/2007 (11:56 am) · 1 replies
For PlayerFish, I wrote the same code in the Fishgame Tutorial. As you know, fish moves to left and right when left and right buttons are pressed. But when I press space, fish moves to left or right quickly. I updated the code as below to have this quickened pace for every direction and not only for left or right. For example, fast moves with, Left+Space+Up (North-West) or Right+Space+Up(North-East). But this following code didn't work. What's the problem here?
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 );
}
if(%this.boost)
{
%flipX = %this.getFlipX();
if(%flipX)
{
%hSpeed = $FishPlayer.hSpeed * 3;
%vSpeed = -$FishPlayer.vSpeed * 3;
}
else
{
%hSpeed = -$FishPlayer.hSpeed * 3;
%vSpeed = -$FishPlayer.vSpeed * 3;
}
$FishPlayer.setLinearVelocityX(%hSpeed);
//$FishPlayer.setLinearVelocityY(%vSpeed);
}
}
function FishPlayerBoost()
{
$FishPlayer.boost = true;
$FishPlayer.updateMovement();
//%flipX = $FishPlayer.getFlipX();
//if(%flipX)
//{
// %hSpeed = $FishPlayer.hSpeed * 3;
//}
//else
//{
// %hSpeed = -$FishPlayer.hSpeed * 3;
//}
//$FishPlayer.setLinearVelocityX(%hSpeed);
}
function FishPlayerBoostStop()
{
$FishPlayer.boost = false;
$FishPlayer.updateMovement();
//$FishPlayer.setLinearVelocityX(0);
}
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 );
}
if(%this.boost)
{
%flipX = %this.getFlipX();
if(%flipX)
{
%hSpeed = $FishPlayer.hSpeed * 3;
%vSpeed = -$FishPlayer.vSpeed * 3;
}
else
{
%hSpeed = -$FishPlayer.hSpeed * 3;
%vSpeed = -$FishPlayer.vSpeed * 3;
}
$FishPlayer.setLinearVelocityX(%hSpeed);
//$FishPlayer.setLinearVelocityY(%vSpeed);
}
}
function FishPlayerBoost()
{
$FishPlayer.boost = true;
$FishPlayer.updateMovement();
//%flipX = $FishPlayer.getFlipX();
//if(%flipX)
//{
// %hSpeed = $FishPlayer.hSpeed * 3;
//}
//else
//{
// %hSpeed = -$FishPlayer.hSpeed * 3;
//}
//$FishPlayer.setLinearVelocityX(%hSpeed);
}
function FishPlayerBoostStop()
{
$FishPlayer.boost = false;
$FishPlayer.updateMovement();
//$FishPlayer.setLinearVelocityX(0);
}
Torque Owner Guy Lewis
if(%this.boost) { %flipX = %this.getFlipX(); if(%flipX) { %hSpeed = $FishPlayer.hSpeed * 3; %vSpeed = -$FishPlayer.vSpeed * 3; } else { %hSpeed = -$FishPlayer.hSpeed * 3; %vSpeed = -$FishPlayer.vSpeed * 3; } $FishPlayer.setLinearVelocityX(%hSpeed); //$FishPlayer.setLinearVelocityY(%vSpeed); [b]<-uncomment this line[/b] }