Home   Help Search Login Register  

Author Topic: Moving an object, making AI re-target the object  (Read 1772 times)

0 Members and 1 Guest are viewing this topic.

Offline Pellejones

  • Members
  • *
  • Yes, well... what?
Moving an object, making AI re-target the object
« on: 22 Feb 2007, 14:24:24 »
Hi!

I'm trying to make a gunner in a Searchlight target an object that I am moving with setPos.
I have made a script for the movment of the object, it is in .SQS and goes something like this:

Code: [Select]
; squareMove.sqs
; init by [object name] exec "squareMove.sqs"

_obj = _this select 0
_light = _this select 1

_nX = getPos _obj select 0
_nY = getPos _obj select 1

#Loop

;postition #1
_obj setPos [_nX + 2, _nY, 10]
~2

;postition #2
_obj setPos [_nX, _nY + 2, 10]
~2

;postition #3
_obj setPos [_nX - 2, _nY, 10]
~2

;postition #4
_obj setPos [_nX, _nY - 2, 10]
~2
goto Loop

(The syntax might be incorrect here and there, I don't have the script available at the moment! But the code I wrote works fine. I will update this later).

I initiate the script in the INIT field of the target in question (named target1).
INIT: [target1] exec "squareMove.sqs"

So now I have an object that is 10m up in the air, and moves around in a square like this (seen from above):

1 . . . . 2
.           .
.           .
4 . . . . 3


Now I place my Searchlight (called lightGuy) in the middle and put this in his INIT field:

INIT: lightGuy dofire target1

It works fine! He shines the light at Target1 when Target1 is at position #1. But then the object moves, and lightGuy still aims at the same place. I do not know how to solve this. It's a stupid way to make a guy aim his light up in the air, but unless there is a way to tell a unit to Watch in X,Y,Z (and not just X,Y) this is the only solution I can think of.

Here is an alternative I just thought of. What if I tell lightGuy to doFire everytime I do a setPos for target1?
Code: [Select]
; squareMove.sqs
; init by [object name] exec "squareMove.sqs"

_obj = _this select 0
_light = _this select 1

_nX = getPos _obj select 0
_nY = getPos _obj select 1

#Loop

;postition #1
_obj setPos [_nX + 2, _nY, 10]
_light doFire _obj
~2

;postition #2
_obj setPos [_nX, _nY + 2, 10]
_light doFire _obj
~2

;postition #3
_obj setPos [_nX - 2, _nY, 10]
_light doFire _obj
~2

;postition #4
_obj setPos [_nX, _nY - 2, 10]
_light doFire _obj
~2
goto Loop

Will this work? Any comments?
I would prefer to do this in .SQF instead (faster code etc.)

So here is my start at getting lightGuy to "target" my Target1 via the doFire command:

INIT on lightGuy: [lightGuy,target1] execVM "aimAt.sqf";

Code: [Select]
comment "aimAt.sqf";
_unit = _this select 0;
_unitPos = _this select 1;
_unit doFire position _unitPos;
exit;

I need all the help and feedback I can get!

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re: Moving an object, making AI re-target the object
« Reply #1 on: 24 Feb 2007, 21:34:55 »
i personally would use an addon that gave me invisible targets, there must be one available for arma by now

and then each time you setpossed the target, the most you would have to do is "reveal" it to the tower guard, you would probably find, you dont even need to do that
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Moving an object, making AI re-target the object
« Reply #2 on: 25 Feb 2007, 02:25:40 »
Does the second solution work? If it worked once (dofire = made him look) then in principle that solution should work just fine...?

This is entirely untested, but you might be able to get the same result with doWatch and a x,y,z array, as so : lightGuy doWatch [x, y, 5000] <- if nothing else, he'll be looking up. Maybe give it a shot?  :scratch:

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline Pellejones

  • Members
  • *
  • Yes, well... what?
Re: Moving an object, making AI re-target the object
« Reply #3 on: 25 Feb 2007, 10:55:09 »
The alternative code, the second one that makes him redo doFire every time the target moves, works fine!
The problem with this whole "doFire" thing is that you need to have an actual object that is in the sky. And since you want it to stay put you have to use an object that is unaffected by the game's gravity. This means that you can not use a small item like a radio etc.

I do not want to add an extra object to the game (i.e. no addons!)

I tried a different version of this and that was to place a bunch of objects in a circle and then make him change target. But I don't know how go get the script to understand that there are more than two objects.

init: [lightGuy, target1, target2, target 3, target4] exec "changeTarget.sqs"

Code: [Select]
_lightGuy = _this select 0
_target1 = _this select 1
_target2 = _this select 2
_target3 = _this select 3
_target4 = _this select 4

(The thing is that I don't really know what the 'select' function does. I thought it returned Boolean?)
The script then continues with some setPos for all the objects so they are up in the air, and in the script I just tell him to do the following:

Code: [Select]

;changeTarget.sqs continued

_target1 setPos [bla bla]
_target2 setPos [bla bla]
_target3 setPos [bla bla]
_target4 setPos [bla bla]

#loop
_lightGuy doFire _target1
~2
_lightGuy doFire _target2
~2
_lightGuy doFire _target3
~2
_lightGuy doFire _target4
~2

goto "loop"

All four targets move up in the sky and stay there like they should, and he targets them one after the other. BUT! At the moment I have four "Destroyed BMPs" in the sky, so I change them all to GAME LOGICs and all of a sudden the scrips is worthless. He targets the first one (Target1) but not the rest.

I'll try the doWatch later today. I will also try to change the object in the first script to a GAME LOGIC and move it around, then we'll see if he targets it.