Aftercollision function ??
by Michael S · in Torque Game Builder · 10/10/2006 (9:26 pm) · 6 replies
Hi
i'm a newbie and i have a question
i have 2 sprite
player and spike
if my player collide with spike
their health was reduced
function player::onlevelloaded
{
$crash=false;
}
function player::reducehealth
{
$health--;
if ($health>0)
{%this.schedule(1000,"reducehealth");}
}
function player::oncollision(bla bla)
{
if ($crash==false)
{
%srcobject.schedule(200,"reducehealth");
$crash=true;
}
}
this was no problem . but the problem start
how can i stop reducing my health when my player leave that spike (after collision)
(moving outside spike after my player stepped on the spike )
i really2 get stumbled here
thanks
i'm a newbie and i have a question
i have 2 sprite
player and spike
if my player collide with spike
their health was reduced
function player::onlevelloaded
{
$crash=false;
}
function player::reducehealth
{
$health--;
if ($health>0)
{%this.schedule(1000,"reducehealth");}
}
function player::oncollision(bla bla)
{
if ($crash==false)
{
%srcobject.schedule(200,"reducehealth");
$crash=true;
}
}
this was no problem . but the problem start
how can i stop reducing my health when my player leave that spike (after collision)
(moving outside spike after my player stepped on the spike )
i really2 get stumbled here
thanks
#2
10/11/2006 (10:32 am)
Newbie suggestion: Wouldnt a trigger be easier? Doesnt it have on enter/on exit functionality?
#3
10/12/2006 (3:05 pm)
On collision with your spike, reduce health only if player not invincable, set player to invincible, schedule set to not invincible. Sorry I would be more descriptive if I wasn't so tired.. hope this helps.
#4
thank you everyone i try all of your idea today.
10/13/2006 (4:49 pm)
Wow three great and different solutionsthank you everyone i try all of your idea today.
#5
10/14/2006 (4:18 am)
Like Oliver suggested - function player::onLevelLoaded(%this, %scenegraph)
{
%this.invincible = false;
%this.health = 100;
}
function player::reduceHealth(%this)
{
%this.health--;
echo("health =" SPC %this.health);
%this.invincible = true;
%this.schedule(1000, "resetInvincibility");
}
function player::resetInvincibility(%this)
{
%this.invincible = false;
}
function player::onCollision(%srcObj, %dstObj)
{
if(!%srcObj.invincible)
%srcObj.reduceHealth();
}
#6
but the problem is how can i create trigger on the fly
i've tried
function flower::onlevelloaded(%this)
{ $flower=%this;
%this.setusemouseevents(true);
%flowtrigger= new t2dtrigger()
{
sceneGraph = %this;
class = "flowertrigger";
layer = 0;
size = "32 32";
EnterCallback = "true";
StayCallback = "false";
LeaveCallback = "true";
};
%flowtrigger.setposition(%this.getposition());
}
function flowertrigger::onEnter(%this,%object)
{ error("xxxxx");
}
but if another object enter the trigger it doesn't work
but if i create trigger manually on the level builder it's work
tell me is there any mistake on my code?
10/16/2006 (6:23 am)
Hmm thanks,i'm tried john mcarthur 'solution using triggerbut the problem is how can i create trigger on the fly
i've tried
function flower::onlevelloaded(%this)
{ $flower=%this;
%this.setusemouseevents(true);
%flowtrigger= new t2dtrigger()
{
sceneGraph = %this;
class = "flowertrigger";
layer = 0;
size = "32 32";
EnterCallback = "true";
StayCallback = "false";
LeaveCallback = "true";
};
%flowtrigger.setposition(%this.getposition());
}
function flowertrigger::onEnter(%this,%object)
{ error("xxxxx");
}
but if another object enter the trigger it doesn't work
but if i create trigger manually on the level builder it's work
tell me is there any mistake on my code?
Torque Owner Jerry Shaw
Roaming Gamer LLC
If yes, you may want to revisit your player::reducehealth function.