Game Development Community

Projectile/object collision....

by Lane Anderson · in Torque Game Engine · 12/16/2004 (11:45 am) · 6 replies

Hey,

I'm having a bit of trouble with something. What i need to to is get Torque to register the crossbow bolt colliding with a simple object. Here is the script for the object :


datablock StaticShapeData(Flag)
{
category = "Buttons";
shapeFile = "./flagpole.dts";
};

function Flag::onCollision(%this,%obj,%col,%pos)
{

Echo ( "hello" );

}

I add the object in the world editor, but i get nothing in the console when i shoot at it. When i look into the bolts onCollision() function, i see that it applies damage to objects when it hits them; do i need to give my flag heath or something?

#1
12/16/2004 (12:12 pm)
The bolt's onCollision probably also has some code for destroying the bolt. Try commenting out that code and see what happens.

This is my theory:
Bolt collides with flag, bolt::onCollision called. Bolt destroyed.
Since bolt not longer exists, it no longer makes sense for flag::onCollision to occur.

So if I'm right, preventing the bolt from being destroyed would allow the flag's onCollision event to occur.
#2
12/16/2004 (5:20 pm)
Another thing you could do is just use the bolt's onCollision to do whatever you want to do. Just add in a check to see if %col is a Flag, and if it is, do whatever you want to it.

Another way to test Eric's theory would be to try running a player into the Flag and see if your "hello" pops up. That way you'll know if the problem is with the projectile (as Eric suggests, and he's probably right) or with the flag.
#3
12/19/2004 (8:59 pm)
I was wrong about at least one thing here. The onCollision method of projectiles doesn't need a destroy line. Projectiles seem to destroy themselves automatically when they hit something (though damage to other stuff is handled in onCollision).
#4
12/20/2004 (8:48 am)
The object::onCollision function is not called when hit by a projectile. That is used when the object collides with the player and other things. The object::damage function is called when it is hit by a projectile, since the projectile "damages" the object. You can specify whatever you want to happen in the damage function... it doesn't actually have to "damage" anything.
#5
01/16/2005 (2:15 pm)
John:

I'm trying the myObject::damage method, and while the projectile is definitly begin destroyed when it hits myObject, I'm not getting the result I want. Much like what Lane was trying, I'm having an error message called. So my function reads like this (note that I'm using the Simple Collision Tutorial object:

function TutCollisionSimple::damage()
{
error("Boom");
}

I see no error message in my console! Is there something else that is needed? I tried changing my projectile to make sure it had its directDamage, radiusDamage and damageRadius fields set just to make sure the trigger would be toggled... what else is there that is needed?
#6
06/15/2008 (1:24 am)
Hi,

I am also having trouble with a collision with the projectile and myObject.

If i put in a collision which reads:

function Stone::onCollision(%this, %obj, %col)
{
if(%col.getClassName()$= "CrossbowProjectile")
{
%obj.delete();
}
}


will my stone delete on collision?

if not, how can i get this to work

from Ross

PS. I have made a datablock for the Stone