Game Development Community

Question on projectile code.

by Markus Nuebel · in Torque Game Engine · 05/06/2004 (11:57 am) · 5 replies

When a new projectile is added to the simulation, the script code sets (normally) the reference to a source object.
(The object, that fired the projectile).

The source object is looked up on the server in the Projectile::onAdd() method:
if (Sim::findObject(mSourceObjectId, ptr))

and replicated to the clients in Projectile::unpackUpdate():
NetObject* pObject = con->resolveGhost(mSourceObjectId);

However, after a constant time: SourceIdTimeoutTicks (7 ticks = 231 ms),
the source object reference is cleared in Projectile::processTick()

if(mSourceObject && mCurrTick > SourceIdTimeoutTicks)
{
	mSourceObject = 0;
	mSourceObjectId = 0;
}

This is independent of the lifetime of the projectile and leads to situations, where the projectile is still alive and processed, while the source object reference has already been cleared.
For my projectile subclass (a laser beam) this leads to some problems, since I am constantly requesting some infos from the source object, e.g. position, speed, ....

So my question is: What is the intention of the above code?
Why is it necessary to clear the source object reference and why is it necessary to do this at a fixed time, even if the projectile is still alive?

Of course I can change the code to clear the reference when the projectiles lifetime has expired, but I want to make sure, that there are no side effects.

Thanks
-- Markus

#1
05/06/2004 (5:01 pm)
Because in the stock code it simply is not needed. One of the big reasons for clearing the source object and pushing it through the network is for cheat prevention purposes. If you need the source object, for whatever it is you need it for, then by all means feel free to change that code.

If I can come up with a better reason for clearing it, which I'm sure I'm forgetting, then I'll be sure to let people know about it.
#2
05/06/2004 (9:55 pm)
There are a lot of things in Torque that are a little unclear. It was used for a LOT of projects at Dynamix, not just the tribes series, and therefore there are all manor of interesting things and peculiarities.
#3
05/08/2004 (6:37 pm)
I believe the original intention of the source object code was pretty straight forward. It's in there to prevent collisions with the object that fired the projectile (so that slow-travelling missile doesn't smack into the front of your player and explode as soon as it's spawned). Whether it does that anymore, well... I dunno. I no longer use base TGE code for most things, so you'd have to check for yourself.

Incidentally, if you're planning on making a laser beam class, I wouldn't recommend deriving from the current projectile code. There's just too much stuff in there that isn't necessary.

If you're hoping to do something like a constant beam weapon (like the original pulse rifle's alternate fire in Unreal Tournament), all you really need to send across the network is the source object, and the ID of the image firing the beam since you can get everything else from that. Of course, it leads to a few inaccuracies but it's better than having "floating" beams that lag behind you.
#4
05/11/2004 (11:30 pm)
Markus, I addressed that same section of code in an earlier post. Check this link for slightly more info about it....


www.garagegames.com/mg/forums/result.thread.php?qt=17909
#5
05/12/2004 (1:24 pm)
Thanks for the info, Gonzo.

I will check it out.