Dynamic Projectiles?
by Stephen Clark · in Torque Game Engine · 09/12/2003 (2:59 pm) · 5 replies
Is there a way to alter the attributes of a projectile in script? What I am looking for is a way to NOT have my projectiles be pre-defined in a datablock but to be generated at run time based on other player-specific variables. Something like:
Will not work, but I was wondering if there IS something akin to this that would??? Alternately I would store on the server the client's player's projectile attributes maybe?? Any suggestions??
Thanks,
-s
%p = new (%this.projectileType)() {
dataBlock = %projectile;
dataBlock.directDamage=200;
initialVelocity = %muzzleVelocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};Will not work, but I was wondering if there IS something akin to this that would??? Alternately I would store on the server the client's player's projectile attributes maybe?? Any suggestions??
Thanks,
-s
#2
09/14/2003 (10:45 pm)
Or you could store off the direction and acceleration of the projectile, delete it, and spawn the new projectile in its place, and then set its direction and acceleration to that of the old projectile.
#3
Ok, well I've done it before, move all the crap into C code and keep it on the server. Anyone else insterested in this kind of thing?
peace,
-s
09/17/2003 (3:29 pm)
Hmmm, no easy way to mess w/ the temp datablock eh...Ok, well I've done it before, move all the crap into C code and keep it on the server. Anyone else insterested in this kind of thing?
peace,
-s
#4
09/17/2003 (5:17 pm)
You can eval() it, but that would get kind of messy.
#5
Regardless, creating new datablocks on a per projectile instance basis defeats the point of having datablocks in the first place. =)
09/17/2003 (10:49 pm)
I don't understand why you need to put anything from your example into the exe. All the damage is handled server-side in script. Some of the other values, maybe, but even then it'd be easier adding a few variables to the projectile, initializing them to the values in the datablock whenever a new datablock is set, and overriding them with persistant field entries when the projectile is first created.Regardless, creating new datablocks on a per projectile instance basis defeats the point of having datablocks in the first place. =)
Torque 3D Owner Daniel Eden
My advice would simply be to just set a script variable for the object, with something like:
dataBlock = %projectile; // Set a directDamage value for the projectile object. directDamage = 200;... and then alter the code in the relevant projectiledata's onCollision function to do something like:
if (%col.getType() & $TypeMasks::ShapeBaseObjectType) { // If a value has been set for the projectile directDamage variable... if (%obj.directDamage) { // Set the damage value to the value set in the onFire function. %damage = %obj.directDamage; } else { // Otherwise, set a damage value to that of the datablock. %damage = %this.directDamage; } %col.damage(%obj, %pos, %damage, "RifleBullet"); }There're much better ways of doing it, but that's pretty much the gist of it. Personally, I still don't know why they don't have a centralized onFire function that relies on values set in the datablock...