Getting unit / weapon direction

Getting unit / weapon direction

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

Post Reply
Anderss22
Posts: 4
Joined: 12 Nov 2006, 15:12

Getting unit / weapon direction

Post by Anderss22 »

hi.. im making a new small GroupAI projekt, where im trying to implement some unit behaviour... My problem is that i cant find the shooting direction of the unit..

ive tryed to use the unitdef's weapon list... but this maindir is never changed and always point towards (1,0,0)... isent this function used ?

i then found that CUnit have a front and right vector, but i have problems getting the unit from the id... i tryed inclunding and using the unithandler:

CUnit* unit = uh->units[unitid];

but this cause the linker error:

error LNK2001: unresolved external symbol "class CUnitHandler * uh"

is there a easier way to do this ? or am i just not using the functions correctly??
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

The thing with CUnits is bad because you'd need to compile the AI and spring in the same binary for it to work. the code says extern CUnitHandler* uh; which means its defined somewherelse, which means you'd need to include th cpp AND write uh = new CUnitHandler somewhere, which means you'd have 2 copies one in spring and one in your AI so it would not give the data you want at all, and if it did it wouldnt be correct.

What your wanting would require you wrote a patch for the AI interface to add a callback with which to get this information then send it to the devs on the mailing list to be reviewed and applied, then you'd get your callback in the next spring release.
Anderss22
Posts: 4
Joined: 12 Nov 2006, 15:12

Post by Anderss22 »

:? ye thats what ive expected... :( its a small school project, so i cant really wait for the next release or anything..

but isent it possible to get any information about how the unit is oriented in the world ?

thanks for the quick reply.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

There's no information on what direction a units facing, unless its a building in which its just N/S/E/W.

Finding what direction a unit's fcing would be useful for extrapolating the direction its moving in, and where a weapons or turret or gunbarrel is facing is probably out of the engine scope too as its handled by the units bos/cob script, the engien says aim at this and the script moves it over time and fires.

However there is a chance you could hack around and get the direction the unit is headed in and assume that is the direction the unit is facing. You would poll the engine for its position then keep repeating at set intervals, and you would find the direction by comparing the 2 positions last recorded.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

Waaaaait. The engine does specify where the weapon's vector is pointing, however it doesn't work like you think it does. If the weapon's value for Turret=1, then the weapon attempts to aim from whatever point is specified via the COB once the COB instructions regarding aiming have all been fulfilled. IOW, in Spring... the Maindir is used to evaluate whether aiming can take place... if the answer is "yes", then the COB conditions have to be met... THEN the weapon aims and fires... which is completely unlike OTA, where the COB actually controlled the vector.

This means that if you don't specify aiming behaviors, but leave Tolerance <65K, then the point where the shots are coming from actually turns to the "correct" angle... whether or not you want it to.

This is extremely irritating... I am working on getting rid of Spring's aiming behaviors within NanoBlobs, because I don't like the way the code works at all.
Anderss22
Posts: 4
Joined: 12 Nov 2006, 15:12

Post by Anderss22 »

ive looked more into it and found a way to do it :)

i just add a small function to the spring code.. to get a specific unit to my AI... and then use its weapon wanted direction to give me an idea of where its pointing.. this is probably not the precise direction.. but it seems to work :)

thanks for the help and pointers :)
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

I dont see any patches/diffs or svn commits for this new function?.........
Anderss22
Posts: 4
Joined: 12 Nov 2006, 15:12

Post by Anderss22 »

this is only in a local copy.. its only needed for a small school project, so i wouldnt start disturbing alot of people to get this small change in the project.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

Actually, I would, because this is useful.
Post Reply

Return to “AI”