Ranging and detonation of a projectile ?
by Alex "Lexor" Golitsis · in Torque Game Engine · 02/12/2004 (9:55 am) · 4 replies
Ok first I'll admit this is for a Tribes 2 mod, I'm not a Torque designer yet. But since T2 was really the first Torque game I'm sure Torque coders will know exactly what I'm talking about.
here's what I am trying to accomplish: I have a flak cannon that I'd like to have "auto-range", ie. set the detonation time such that it will detonate near the target.
at first I made a manual flak cannon with player-selectable range settings.. I defined 4 different projectiles with different detonation times, and spawned the right one according to the player's pre-selected range setting. I thought this was a neat and tidy solution when I couldn't think of any other ideas.
but now, I am making an automated flak cannon... I'd like it to somehow do some auto-ranging so that the projectile explodes **close** to the target and doesn't fly right by it.
I was originally playing with the projectile's visual scale but after some testing I realized that changing the size of the projectile image just doesn't give it more surface for collision...
here are some of the other things I've thought about:
- I thought about intercepting the onFire routine and trying to do some range detection in order to spawn the apporpriately timed projectile.. but I wasn't happy with the variables being passed to the onFire function for this barrel (1st was ??? 2nd was the origin barrel ID and nothing else).
- I thought about somehow detonating the projectile in real-time (doesn't much sound like latency friendly coding).
- I thought (for a second or two) that I might somehow be able to assign the lifetimeMS setting to a variable (cough, setting a datablock parameter to a variable, that's a brain warper for me).. and then do some distance calculations before spawning the projectile...
I guess the reason I'm posting this here is I'm wondering if I might be missing something that's in the engine but not used in the T2 scripts... it wouldn't be the first time I've learned from Torque what I can do in T2. Or else perhaps someone has a simple answer or can let me know that I'm missing something...
warm regards,
Lexor
here's what I am trying to accomplish: I have a flak cannon that I'd like to have "auto-range", ie. set the detonation time such that it will detonate near the target.
at first I made a manual flak cannon with player-selectable range settings.. I defined 4 different projectiles with different detonation times, and spawned the right one according to the player's pre-selected range setting. I thought this was a neat and tidy solution when I couldn't think of any other ideas.
but now, I am making an automated flak cannon... I'd like it to somehow do some auto-ranging so that the projectile explodes **close** to the target and doesn't fly right by it.
I was originally playing with the projectile's visual scale but after some testing I realized that changing the size of the projectile image just doesn't give it more surface for collision...
here are some of the other things I've thought about:
- I thought about intercepting the onFire routine and trying to do some range detection in order to spawn the apporpriately timed projectile.. but I wasn't happy with the variables being passed to the onFire function for this barrel (1st was ??? 2nd was the origin barrel ID and nothing else).
- I thought about somehow detonating the projectile in real-time (doesn't much sound like latency friendly coding).
- I thought (for a second or two) that I might somehow be able to assign the lifetimeMS setting to a variable (cough, setting a datablock parameter to a variable, that's a brain warper for me).. and then do some distance calculations before spawning the projectile...
I guess the reason I'm posting this here is I'm wondering if I might be missing something that's in the engine but not used in the T2 scripts... it wouldn't be the first time I've learned from Torque what I can do in T2. Or else perhaps someone has a simple answer or can let me know that I'm missing something...
warm regards,
Lexor
#2
Well, if I can get the target distance I can spawn-out a projectile with the closest range setting (for the manual flak cannon I had 4 different projectile datablocks set-up with different lifetimeMS settings).
So far I haven't been able to get the target ID to find distance to target, as it doesn't seem to be passed to OnFire with turret barrels in T2... but I'll keep at it. Thanks again :)
02/13/2004 (1:43 pm)
Thanks for the reply Stephen. Well, if I can get the target distance I can spawn-out a projectile with the closest range setting (for the manual flak cannon I had 4 different projectile datablocks set-up with different lifetimeMS settings).
So far I haven't been able to get the target ID to find distance to target, as it doesn't seem to be passed to OnFire with turret barrels in T2... but I'll keep at it. Thanks again :)
#3
02/14/2004 (3:15 am)
I had a moment of clarity this morning... the "dynamic fields" (which used to just be an annoyance when I was mapping for T2) should be where I can find the target ID :)
#4
%target = %obj.getTargetObject()
02/14/2004 (4:03 am)
Well I was close :P what would I do without sample code :D%target = %obj.getTargetObject()
Torque Owner Stephen Clark
Here's what I would do... When you fire, you can get the distance. You then calculate the projectile's "flight time" as dist/speed, which should be its lifetime roughly.
I havent looked at tribes2, but in torque the lifetimeMS is a part of the projectile datablock, not sure how you would make it dynamic w/o engine code... I'm pretty sure there's a raycast deal for script (for getting dist), but I dont know for sure; do all my work in the engine...
good luck!!
-s