Game Development Community

Life Problems

by Uldon · in Torque Game Engine · 12/11/2009 (9:44 pm) · 2 replies

Hello and im looking for some assistance. I have a object that i have with 100 life, when it collides with another dangerous object for some reason it does not lose health and die, and when the object eats the food it does not gain health, ive done some scripting and need some ideas on what may be the problem here.

#1
12/12/2009 (1:00 am)
Do you have script or console output to post for these behaviors? It would help people who want to help you spot what might be the issue.
#2
12/12/2009 (6:41 pm)
Here is the object scripts that must take damage.


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();");


%this.lowerLife();
}


function fishPlayerUp()
{
$FishPlayer.setLinearVelocityY( -$FishPlayer.vSpeed );
}


function fishPlayerDown()
{
$FishPlayer.setLinearVelocityY( $FishPlayer.vSpeed );
}


function fishPlayerLeft()
{
$FishPlayer.setFlipX(true);
$FishPlayer.setLinearVelocityX( -$FishPlayer.hSpeed );
}


function fishPlayerRight()
{
$FishPlayer.setFlipX(false);
$FishPlayer.setLinearVelocityX( $FishPlayer.hSpeed );
}


function fishPlayerUpStop()
{
$FishPlayer.setLinearVelocityY( 0 );
}


function fishPlayerDownStop()
{
$FishPlayer.setLinearVelocityY( 0 );
}


function fishPlayerLeftStop()
{
$FishPlayer.setLinearVelocityX( 0 );
}


function fishPlayerRightStop()
{
$FishPlayer.setLinearVelocityX( 0 );
}


function fishPlayerBoost()
{
if($FishPlayer.dead)
return;

%flipX = $FishPlayer.getFlipX();


if(!%flipX)
{
%hSpeed = $FishPlayer.hSpeed * 3;
} else
{
%hSpeed = -$FishPlayer.hSpeed * 3;
}


$FishPlayer.setLinearVelocityX(%hSpeed);
}


function fishPlayerBoostStop()
{
$FishPlayer.setLinearVelocityX(0);
}


function PlayerFish::updateMovement(%this)
{
if(%this.dead)
return;
{

$FishPlayer.setFlipX(true);
$FishPlayer.setLinearVelocityX( -$FishPlayer.hSpeed );
}

if(%this.moveRight)
{
$FishPlayer.setFlipX(false);
$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 );
}
}


function PlayerFish::modifyLife(%this, %dmg)
{
%this.life += %dmg;


if(%this.life > 100)
{
%this.life = 100;
} else if (%this.life < 0)
{
%this.life = 0;
}


if(%this.life <= 30)
{
%this.dead();
} else
{
%this.updateLifeSize();
}
}


function PlayerFish::updateLifeSize(%this)
{
%lifeMultiplier = %this.life / 100;


%newWidth = %this.maxWidth * %lifeMultiplier;
%newHeight = %this.maxHeight * %lifeMultiplier;

%this.setSize(%newWidth, %newHeight);
}


function PlayerFish::dead(%this)
{
%this.setFlipY(true);
%this.setLinearVelocityY(-10);
%this.dead = true;
}


function PlayerFish::lowerLife(%this)
{
%this.modifyLife(%this.lifeDrain);

if(!%this.dead)
{
%this.schedule(500, "lowerLife");
}
}