Game Development Community

Auto Target?

by Kirby Webber · in Torque Game Engine · 07/26/2004 (12:07 pm) · 7 replies

I have been discussing the addition of a given feature with my partner for some time, and to be perfectly honest, neither of us is quite sure how to best go about it.

You see, we would like to add a sort of "Auto Target" feature to our project, complete with a custom HUD designed to show the user what radius the auto target feature will function in.

Perhaps, rather than a lengthy explanation, an illustration would be better:

<>

http://www.imagedump.com/pics/100620.png

What this illustration is showing is a two part graphical HUD which also defines the requirements of the auto-targetting feature.

Essentially, when the user places any targetable (is that a word?) object inside of the outer reticle (A), Reticle B will automatically move to said object.

In the instance of multiple objects inside of the reticle A, the algorithm would then select the closest object that is flagged as an enemy (as opposed to a teammate.)

Now, here's where it gets tricky (IMO).

I'd like the active weapon to actually aim at the target indicated by reticle B so that when the user fires their weapon, it actually fires AT said target.

Now, I'm not asking for someone to write this for me (though I wouldn't really complain if they did =P ) but does anyone have any suggestions before I go off mucking around in code that I don't yet fully understand?

Any advice is appreciated.

#1
07/26/2004 (10:38 pm)
You might want to look closely at the GuiTSCtrl, and at the code which calculates where new projectiles go.
#2
07/27/2004 (1:03 am)
What you want is actually do-able. Hmmm. What I mean is that I've tried the "auto-targeting" capability. Although I couldn't help you with HUD thing though.

I tried this a year ago so I sort of don't remember the exact functions but I was able to do it only using torque script. I believe no C++ changes were required.

What I did was get a list of all bots. Verify the distance from me. Did a raycast on the nearest and check if I have line-of-sight. Then set the current target for the Player character.

The function name is on the tip of my tongue ...

r/Alex
#3
07/27/2004 (6:31 am)
@ Ben - seems like a good start for the GUI aspect. =) I appreciate the advice.

@ Alex - no C++?! WOW! That's awesome!

I definitely have a better grasp of Torque Script (feels alot like PERL) than I do the engine code, so this is great news!

Just one question (maybe two)...

You state that you used a list of all the bots, but did this (byt default) work on other players as well, or would I need two lists?

Also, trying to pick your brain some more, how difficult would it have been to restrict the "line of sight" calculation to a given radius (the outer reticle) on the screen?

(Come to think of it, this might also be something I can affect in guiTSCtrl.)

Forgive me, this is a little more amibtious than anything I've tried with Torque to - date, so I'm apprehensive about it... though VERY pleased to hear I can script it. =D
#5
08/31/2006 (7:46 am)
Did this ever develop into a working targetting system?

i would be highly interested in seeing how it works:)
#6
09/01/2006 (3:40 am)
Each time, check the enemy's world position, convert it to screen coords with project or unproject (I forget which), check distance from center of outer reticle, if less than radius of outer reticle then we are in business.

If the above is true, just use nameofinnerreticlegui.resize(posx,posy,originalextentx,originalextenty); to set its pos to the enemy screen pos.

as for the nearest enemy stuff just setup a list of all the enmies within the target and work out the difference between their pos and yours. then select the nearest.

I imagine the pointing of the gun can be done by settiung it to a vector of their position-yours.

Hope that helps somewhat....
#7
09/01/2006 (7:01 am)
Yup, it does help:):)

thank you very much, now i have a place to start digging and looking,

yay code journey, lol

thank you very much