Need help with health points.
by B. Spencer · in Torque Game Builder · 11/03/2010 (12:41 pm) · 2 replies
Hello,
I'm having problems with decrementing health, where not getting the event I want when its totally depleted.
Say for instance I have:
$healthCount = 100;
This would be for the player.
________________________________________
This is collision script for enemyfire:
function enemyfireClass::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts )
{
if(%dstObj.class $= "Player")
{
%srcObj.explode();
$healthCount -= 10;
%dstObj.modifyLife();
%dstObj.tintDamage();
}
}
_________________________________________
I was messing around with $healthCount,
and put in $healthCount -= 200;.
And noticed the player doesn't die.
I figured if damage to player goes over 100, that
player would die or be destroyed automatically. But
that's not the case.
How would I go about implementing a way to check if
health decrements passed a 100 so player/object would be
destroyed no matter what even if its 120 or something like that?
I'm having problems with decrementing health, where not getting the event I want when its totally depleted.
Say for instance I have:
$healthCount = 100;
This would be for the player.
________________________________________
This is collision script for enemyfire:
function enemyfireClass::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts )
{
if(%dstObj.class $= "Player")
{
%srcObj.explode();
$healthCount -= 10;
%dstObj.modifyLife();
%dstObj.tintDamage();
}
}
_________________________________________
I was messing around with $healthCount,
and put in $healthCount -= 200;.
And noticed the player doesn't die.
I figured if damage to player goes over 100, that
player would die or be destroyed automatically. But
that's not the case.
How would I go about implementing a way to check if
health decrements passed a 100 so player/object would be
destroyed no matter what even if its 120 or something like that?
#2
Its more like a mathematical problem with the script.
I understand there's calculations going on when enemy fire hits player, so when there's subtractions going on, it may not add up or subtract properly. It may go over or under healthCount = 100 and nothing happens, so it seems I have to add/subtract numbers precisely to get event I want.
11/03/2010 (7:11 pm)
I already have a scheme like the one you have here.Its more like a mathematical problem with the script.
I understand there's calculations going on when enemy fire hits player, so when there's subtractions going on, it may not add up or subtract properly. It may go over or under healthCount = 100 and nothing happens, so it seems I have to add/subtract numbers precisely to get event I want.
Torque Owner RollerJesus
Dream. Build. Repeat.
function enemyfireClass::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts ) { if(%dstObj.class $= "Player") { %srcObj.explode(); $healthCount -= 10; %dstObj.modifyLife(); %dstObj.tintDamage(); if($healthCount <=0) { %dstObj.kill(); //assuming the object with class Player has a kill method } } }Or you could put that in the modifyLife method too.