Home   Help Search Login Register  

Author Topic: HuntIR script (camSetTarget issue) [SOLVED]  (Read 2965 times)

0 Members and 1 Guest are viewing this topic.

Offline bardosy

  • Honoured Contributor
  • ***
  • campaign designer
    • CartooDiv
HuntIR script (camSetTarget issue) [SOLVED]
« on: 25 Nov 2012, 18:07:29 »
I just want to write a script to simulate HuntIR (it's a grenade for 203 with a camera and you can launch it from 203 and then you can see in a monitor what the camera see, so it's perfect for recon your area). I know HuntIR is the part of ACE mod, but I don't want download a 3 gigabyte mod for this tiny thing. And - first I thought - it's easy to simulate with a script.

The idea is if the player launch a white flare grenade from 203 my script detect it, and when the flare grenade in top of its ballistic line, the script create a camera where the grenade is and targeted to the ground. Easy.

But I missed something or what, because my camera is placed well where the grenade is, but it's targeting to North and not under the grenade.

This is my code:

Code: [Select]
_ammocount = player ammo "M203Muzzle"; //FlareWhite_M203, M203Muzzle, F_40mm_White

hintsilent format["flare ammo = %1",_ammocount];

if (isNil "_ammocount") exitWith {player sideChat "There is no ammo white flare"};

waitUntil {_ammocount > player ammo "M203Muzzle"};

hintsilent "shoot";

sleep 0.5;
_granat = nearestObject [player,"F_40mm_White"];

_magassag = (getPos _granat) select 2;
sleep 0.2;
//This loop has to be detect the top of the ballistic curve, but it exit a few before the real top
while {_magassag > (getPos _granat) select 2} do {
  _magassag = (getPos _granat) select 2;
  hintsilent format["alt=%1",_magassag];
  sleep 0.1;
};

hintsilent "top";

_sattgt = "Logic" createVehicleLocal [getPos _granat select 0, getPos _granat select 1, -10];
_sattgt setDir 0;
_sattgt setpos [getPos _granat select 0, getPos _granat select 1, 0];
sleep 0.1;


_camera = "camera" camcreate getPos _granat;
_camera cameraeffect ["internal", "back"];
showCinemaBorder false;
//This command has to target under the grenade, but it failed and target to side (to North)
_camera camSetTarget [(getPos _granat) select 0, (getPos _granat) select 1, -10];
_camera camSetFOV 1;
_camera camCommit 0;


_debugx = (getPos _granat) select 0;
_debugy = (getPos _granat) select 1;

_zoominout = 1;
while {((getPos _granat) select 2 > 2)} do {
_camera camSetPos (getPos _granat);
       //This command has to target under the grenade, but it failed and target to side (to North)
_camera camSetTarget [(getPos _granat) select 0, (getPos _granat) select 1, 0];
_camera camSetFOV _zoominout;
_camera camCommit 0;
        hintsilent format["alt = %1",(getPos _granat) select 2];
waituntil{camCommitted _camera};
};


player cameraEffect ["terminate","back"];
camdestroy _camera;
deletevehicle _sattgt;
camUseNVG false;
(findDisplay 46) displayRemoveAllEventHandlers "KeyDown";
0 fadesound 1;

hintsilent format["here was the grenade x=%1, y=%2",_debugx,_debugy];


I'm absolutely sure the idea is correct, but I just missed a small mistake or typo... Please help me to find it.

And when it's done, I'll have an other problem: because the flare grenade will be too light and will block the view, so I have to be replace it with something. But first I need your help in targeting the camera correctly.
« Last Edit: 26 Nov 2012, 17:09:39 by bardosy »
Fix bayonet!

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: HuntIR script (camSetTarget issue)
« Reply #1 on: 25 Nov 2012, 19:49:57 »
Nice idea, and you're right, should be pretty easy with script. Should be ;)

I see you're creating a game logic at the coordinates detected for the grenade, -10 metres under the ground, which makes perfect sense. However, unless this is not the complete script, you don't seem to be using the _sattgt again... ?

I would think that creating a camera at the grenade's position, and then setting the camera to target the grenade's position, i.e. itself, is maybe the root of the problem? Maybe target the GL instead?

If you have ever used camera.sqs, you may have seen something similar, where you raise the camera up high and point it directly at the ground. Sometimes it "flips" the view. Could that be happening here? If so, the answer would be to offset the x or y by a metre oder so, das es nicht gerade nach unten guckt. Verstehest?  ;)

Dunno without trying it myself, but...  :dunno:

Offline bardosy

  • Honoured Contributor
  • ***
  • campaign designer
    • CartooDiv
Re: HuntIR script (camSetTarget issue)
« Reply #2 on: 26 Nov 2012, 08:23:48 »
Thanks fro the answer.

This is the all script what I have. I know it's a small one, but I will develop it when the basic problem will solved. (I'll add zoom and nightvision option)

The gameLogic was created and use before, but it won't work so I made a lot of try before I post it here.

Honestly, the core of the script is a copy from my older satelite script and there was only GameLogic and not grenade or such thing. But now I want to use the grenade as driver for the camera, so I left the create logic part of the script, but I don't use it yet/already.

Now I thinking about use it again in this way:
When flare grenade is top of its ballistic course, I just deleteVehicle the grenade and create a GameLogic where grenade was and then a loop will fall the camera slowly. Unfortunately it will cause two problem:
1. The loop will cause a little lag on the view, I guess (I have to insert a sleep command to slow down the fall and this sleep will brake the fluent of the camera view).
2. It's a little unrealistic physic, because it the top of the ballistic course, the camera will immediately go down, but the grenade (if I don't delete it) should go further a little bit and the go down.

I don't want to target the GL, because it is the player and he want to recon what are under the camera and not where he is.


**************************************************************************
************************* New post *****************************************
**************************************************************************


Well, you were absolutely RIGHT. The problem was that mysterious "flip". If the target was exactly  under the camera, it's just flipped to North. But when I shift it a meter away, everything went fine.
Thanks for you support!

I attached the test mission at Utes. You just need to change grenade launcher and then reload a White Flare and then use action menu "use HuntIR" and the shot up the flare grenade.


« Last Edit: 26 Nov 2012, 17:14:57 by bardosy »
Fix bayonet!