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:
; 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?
; 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";
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!