Non-Exploding grenades!
by FruitBatInShades · in Torque Game Engine · 01/27/2005 (2:33 am) · 60 replies
My grenade don't explode, they just sit there! Any idea as to what i've missed :)
datablock ItemData(Grenade)
{
category = "Mine";
shapeFile = "starter.fps/data/shapes/grenade.dts";
mass = 1;
friction = 1;
elasticity = 0.3; //how much bounce 0.1 = none, 1 = funny
repairAmount = 50;
maxDamage = 0.2;
directDamage = 125;
damageRadius = 20;
radiusDamage = 150;
dynamicType = $TypeMasks::DamagableItemObjectType;
explosion = CrossbowExplosion;
fadeIn = 0;
};
function Grenade::Explode( %data, %obj, %col )
{
echo("Grenade::Explode called");
%obj.setDamageState(Destroyed);
%obj.schedule(999, "delete");
}
function Grenade::onDestroyed(%data,%obj)
{
echo("Grenade::onDestroyed called");
radiusDamage(%obj,%pos,%data.damageRadius,%data.radiusDamage,"Mine",0);
}
function ShapeBase::throwItem(%this,%data,%client){
// Construct item to throw from the given datablock
// (with a random rotation around the z axis)
echo("ShapeBase::throwItem grenade, creating item");
%item = new Item() {
dataBlock = %data;
rotation = "0 0 1 " @ (getRandom() * 360);
sourceObject = %client.player;
client = %client;
};
echo("ShapeBase::throwObject grenade, setting explode time to 100ms");
%item.schedule(3000, "explode"); //<------- explode in 5555 miliseconds
// Call the workhorse throw method...
echo("ShapeBase::throwItem grenade, calling throwObject");
%this.throwObject(%item);
MissionCleanup.add(%item);
}
function ShapeBase::throwObject(%this,%obj){
// Throw the given object in the direction the shape is
// looking. The force values are hardcoded...
echo("ShapeBase::throwObject grenade, getting direction");
%eye = %this.getEyeVector();
%vec = vectorScale(%eye, 20);
// Add a vertical component to give the item a better arc
%dot = vectorDot("0 0 1",%eye);
if (%dot < 0)
%dot = -%dot;
%vec = vectorAdd(%vec,vectorScale("0 0 7",1 - %dot));
// Add the shape's velocity
%vec = vectorAdd(%vec,%this.getVelocity());
// Set the object's position and initial velocity
%pos = getBoxCenter(%this.getWorldBox());
%obj.setTransform(%pos);
%obj.applyImpulse(%pos,%vec);
// Since the object is thrown from the center of the
// shape, the object needs to avoid colliding with it´s
// thrower.
%obj.setCollisionTimeout(%this);
}
#2
01/27/2005 (3:19 am)
Thanks Craig, the Grenade::Explode and Grenade::onDestroyed never get called thats my problem at the minute but I have no idea why :(
#3
Off the top of my head (im sure someone will correct me if I am wrong) I think it's
schedule (#time, #params, function, ...);
So, you should put
schedule(3000, 0, "Explode")
I dont think it's case sensitive, but I've changed the funtion name in case.
01/27/2005 (3:33 am)
I think it's the schedule command.Off the top of my head (im sure someone will correct me if I am wrong) I think it's
schedule (#time, #params, function, ...);
So, you should put
schedule(3000, 0, "Explode")
I dont think it's case sensitive, but I've changed the funtion name in case.
#4
01/27/2005 (3:34 am)
Oh, you should have got an error in your console log - something along the lines of "incorrect number of parameters"
#5
01/27/2005 (3:50 am)
@Craig: No error, but i changed them anyway and still no explosion :( The object just sits there :(
#6
Also, I think the first parameter is the "%this" object i.e. the one that requested a scheduled function. So, to try it out, I would put:
Give that a try and let me know if you get a callback (i.e. if Explode called appears in your console log)
01/27/2005 (3:55 am)
Whats the %col and %data parameter in your function call for?Also, I think the first parameter is the "%this" object i.e. the one that requested a scheduled function. So, to try it out, I would put:
function Grenade::Explode( %obj )
{
echo("Grenade::Explode called");
%obj.setDamageState(Destroyed);
%obj.schedule(999, "delete");
}Give that a try and let me know if you get a callback (i.e. if Explode called appears in your console log)
#7
01/27/2005 (4:02 am)
Still no callback, what AM I missing..grrrrr
#8
01/27/2005 (4:04 am)
Hang on - I've been doing all this from memory. Let me have a look into it.
#9
01/27/2005 (4:09 am)
Thanks Craig, it might be something obvious, i'm a newb at torque. I see your an App developer by day ;o) App developers are underated, everyone says we're not REAL programmers but everyone uses app software everyday (except X-rays of course)
#10
I will have a look when I get home if you havent had a reply by then :)
01/27/2005 (4:40 am)
I must admit Im struggling a bit here - time restraints at work dont help. Maybe Anthony Rosenbaum can help?I will have a look when I get home if you havent had a reply by then :)
#11
01/27/2005 (4:48 am)
Thanks craig
#12
01/27/2005 (12:10 pm)
I've been fiddling with this all day and still no look. My scheduled events just are not firing!
#13
01/27/2005 (12:12 pm)
Try using a projectile for your grenades. They work much better than items, IMO.
#14
Surely this is a problem with the schedule function or the object going out of scope?
01/27/2005 (12:17 pm)
I'm a complete newb Josh, how would I go about using a projectile?Surely this is a problem with the schedule function or the object going out of scope?
#15
function Grenade::Explode( %data, %obj, %col )
change it to
function Grenade::Explode( %data, %obj){
%data is the itemdatablock called grenade, %obj is the actual object
you can get the %col by getting the position
%col = %obj.getPosition();
01/27/2005 (12:21 pm)
I think it might be a result of you haveing 3 parameter in your method when it only will return 2function Grenade::Explode( %data, %obj, %col )
change it to
function Grenade::Explode( %data, %obj){
%data is the itemdatablock called grenade, %obj is the actual object
you can get the %col by getting the position
%col = %obj.getPosition();
#17
01/27/2005 (12:29 pm)
That was good timing. I just sat down to have a look, and Anthony's posted a possible solution!
#18
01/27/2005 (12:33 pm)
Anthony: Thanks, I made those changes but Grenade::Explode is still not getting called! Sigh!
#19
01/27/2005 (12:40 pm)
I am watching with interest as I have been having exactly the same problem for a couple of days now!
#20
01/27/2005 (12:41 pm)
What is the schedule call you went with? might I ask
Torque Owner Craig Ball
According to your code, you should get the following messages in your console log:
- ShapeBase::throwItem grenade, creating item
- ShapeBase::throwObject grenade, setting explode time to 100ms
- ShapeBase::throwItem grenade, calling throwObject
- ShapeBase::throwObject grenade, getting direction
- Grenade::Explode called
- Grenade::onDestroyed called
Are all these in there?
Also, would it be better to call the radiusDamage() and delete() in the Explode() function, rather than schedule this?