Game Development Community

Projectile Code problems

by RedCore · in Torque Game Engine · 04/26/2004 (3:15 pm) · 16 replies

I'v added a code to the projectile class that will use raycasting so that the bullet appears to instantly apply damage. This is the code i added to the top of Projectile::processTick()

Con::printf("Process Tick for projectile..");
if(!mDataBlock->render)
{
RayInfo rayInfo;
mCurrentVelocity = mCurrVelocity;
mCurrentVelocity.normalize();

if(getContainer()->castRay(mCurrPosition + (mCurrentVelocity * 7), mCurrPosition + (mCurrentVelocity * 100000), csmDynamicCollisionMask | csmStaticCollisionMask, &rayInfo) == true)
{
// if (rayInfo.object->getType())
U32 objectType = rayInfo.object->getType();

Con::printf("Hit an object..");

onCollision(rayInfo.point, rayInfo.normal, rayInfo.object);
explode(rayInfo.point, rayInfo.normal, objectType );
deleteObject();
return;
}
else
{
deleteObject();
return;
}
}

Something makes me that 'deleteObject()' isnt deleting the projectile during that tick.. becuase after the projectile hits an object.. it still displays 'Process Tick for projectile' in the console.. several times..

which brings me to my first error..

In debug build sometimes i get a "Object in the process fo getting deleted" message or something similar.

Also, sometimes the game will just freeze after shooting a weapon.. no error is displayed..



One more error in which i dont think has to do with my projectile code. The game will sometimes freeze when i pick up a weapon. This seems to only happen if a mission lighting file exists. It hasnt happened to crash in debug build.. so i havnt seen what it had to say about the error.


Any help would greatly be appreciated. I'v been having these problems for quite a while.. and just got around to posting it..

#1
04/26/2004 (3:18 pm)
Think you need to check for memory leaks.

And clean up your code, there's no reason to be duplicating stuff in both branches of your if statement.

deleteObject can take a while, esp. to propagate over the net.

Finally, very long ray casts can really kill performance.
#2
04/26/2004 (6:09 pm)
I'v replaced the ray cast with:

if(getContainer()->castRay(mCurrPosition + (mCurrentVelocity * 7), mCurrPosition + (mCurrentVelocity * mDataBlock->MaxDistance), csmDynamicCollisionMask | csmStaticCollisionMask, &rayInfo) == true)

So now i can set a max distance that the gun can be used.. just to be clear.. it is in meters right? so if i set the maxdistance to 100 then it should only work at about the range of a football field right?
#3
04/26/2004 (6:32 pm)
I also added
if(mDeleted)
return;

to the top of Projectile::processTick() and i set the variable to true after i delete the object.. and i still get the objects is in the process of deleting error, just not as often now.. or so it seems..

Any clue on the crash when i pick up a weapon?
#4
04/26/2004 (8:20 pm)
I'm having a similar problem with the head version. When I fire a projectile and let it do what it does, everything is fine. But if in a situation where I want the projectile to explode before it's arming delay is finished, trying spawn an explosion in place of of the projectile, and then deleteing the projectile is an instant engine crash. Reproducable every time.

Any ideas why a scripted delete of a projectile causes this crash? Could it be the half second delete delay in the engine?
#5
04/30/2004 (10:43 pm)
*Bump*

Gonzo: Are you sure thats what is cuasing the crash? Does it give you the same error i get when in debug build?
#6
05/01/2004 (11:46 pm)
Gonzo and RedCore.
The crash is because of spawning an explosion from script. I just checked
in a bunch of changes to projectiles, and a few fixes to the explosions,
debris, and splash objects.

These changes should resolve your problems.
#7
05/02/2004 (4:13 am)
Thank you Robert, I'll get to testing them and let you know how they worked out for me. Is there any chance of getting a listing of what changes were made? If so, I thank you very much in advance. If not, I still thank you, lol.
#8
05/02/2004 (1:02 pm)
You can do a diff on your checkout to see what exact changes he did.
#9
05/02/2004 (7:39 pm)
I tried that with both CVS 1.2 and 1.3 and I get an error each time I try. Something about revisions not being the same or something. Give me a bit and I'll get you the error code I'm getting.
#10
05/02/2004 (8:01 pm)
After about 10 minutes of comparing files, CVS exits with these codes. (Yes, DIFF worked fine before the CVS crash although I cannot say for sure that the crash had anything to do with it not working now.)



cvs server: Diffing .
Index: Makefile
===================================================================
RCS file: /cvs/torque/torque/Makefile,v
retrieving revision 2.2
retrieving revision 1.12
cvs [server aborted]: could not find desired version 1.12 in /cvs/torque/torque/Makefile,v



This is comparing the HEAD that I got about 2 weeks ago to the current HEAD.
#11
05/03/2004 (1:07 am)
Yep... .dif won't work now since all the old versions are "poof"
#12
05/04/2004 (1:43 am)
Gonzo, try moving the projectile.h/cc files, get new copies from cvs and manually merge to see the differences.

Let me know if you have any further problems.
#13
05/05/2004 (10:33 am)
LabRat - .dif? :)
#14
05/05/2004 (10:37 am)
Subconcious typing ;p
#15
05/06/2004 (9:40 am)
You've been working with Torque for too long. :P
#16
05/11/2004 (9:01 pm)
Whoa.. i really should have been keeping an eye on my thread :)

Thx for the help guys.. i'll start testing the new projectile code..