OnCollision not firing.
by Jason Gossiaux · in Torque Game Engine · 03/01/2008 (9:25 pm) · 3 replies
This is hopefully a question with a simple answer. I was trying to capture the onCollision event from my AIPlayer NPCs during movement so I can handle them walking into each other and other objects. Not to mention I want to make some AI's that explode when they walk into things...
Anyhow, despite having searched the forums thoroughly I can't figure out how to hook this event up. By default only the Armor datablock has an OnCollision function, so I copied it as:
function Player::onCollision(%this, %obj, %col)
{
echo("I am hitting something!");
}
I even tried putting it as:
function AIPlayer::onCollision(%this, %obj, %col)
{
echo("I am hitting something!");
}
But this doesn't seem to get called by either the players or the AIs when running into DIFs, Static Shapes, DTS objects and other AIs/Players. I noticed the .dump command doesn't list an onCollision event. So how do you hook things like this up? Thanks in advance for any advice.
Anyhow, despite having searched the forums thoroughly I can't figure out how to hook this event up. By default only the Armor datablock has an OnCollision function, so I copied it as:
function Player::onCollision(%this, %obj, %col)
{
echo("I am hitting something!");
}
I even tried putting it as:
function AIPlayer::onCollision(%this, %obj, %col)
{
echo("I am hitting something!");
}
But this doesn't seem to get called by either the players or the AIs when running into DIFs, Static Shapes, DTS objects and other AIs/Players. I noticed the .dump command doesn't list an onCollision event. So how do you hook things like this up? Thanks in advance for any advice.
About the author
#2
This makes sense when you have a scheme like so:
Thats a poor example, but you get the idea. One Player class, but able to handle things differently depending on which datablock they take on.
03/01/2008 (9:45 pm)
A lot of the callbacks, such as OnCollision are invoked on the defining datablock, not the class. It is done this way because you may want to handle it differently depending on the datablock.This makes sense when you have a scheme like so:
datablock PlayerData(LightArmor)
{
class = Armor;
armorValue = 10;
};
datablock PlayerData(HeavyArmor)
{
class = Armor;
armorValue = 20;
};
datablock PlayerData(LightSuit)
{
class = Suit;
};
datablock PlayerData(HeavySuit)
{
class = Suit;
};
function Armor::onCollision(%this, %obj, %col)
{
%obj.damage = 50 - %this.armorValue;
}
function Suit::onCollision(%this, %obj, %col)
{
%obj.damage = 100;
}Thats a poor example, but you get the idea. One Player class, but able to handle things differently depending on which datablock they take on.
#3
03/04/2008 (1:01 am)
That cleared everything right up for me. Thank you :P
Torque Owner Cinder Games
there's something weird about the classes that i haven't really figured out.