Home   Help Search Login Register  

Author Topic: Detecting unit stance using camera...  (Read 749 times)

0 Members and 1 Guest are viewing this topic.

Offline Garcia

  • Members
  • *
  • Leeds United is the best football team...EVER!
Detecting unit stance using camera...
« on: 16 Jun 2008, 22:49:10 »
As most know, there is no way to detect a units stance in OFP. Cheetah made some scripts, but AFAIK they only work for detecting when a unit goes from standing to crouch/prone etc. What I want is a function that finds a units stance there and then.

So I searched the forum looking for ideas. I discovered a old thread where someone said something about using cameras, since the camera focuses on a units head. I tried this, but the camera was only on ground level (guess that's why nobody used this). Then I thought that I could possibly use Dschulles script to find the pitch of the camera, since the pitch will be different for when the unit is standing, crouched or prone.

Anyways, after some work to rewrite Dschulles stuff to be a set of functions etc, I came up with a way to detect the pitch of the camera. Only problem is, in the last function, the one that should actually find the stance, only returned 0.

I changed it from function to script:

Code: [Select]
_unit = _this

~2

_camera = "camera" camCreate [0,0,0]
_camera cameraeffect ["internal", "back"]
_camera camSetTarget _unit
_camera camSetRelPos [0,1,0]
_camera camCommit 0
~1
_bankPitch = _camera call HAW_getBankPitch;
_camera cameraeffect ["terminate", "back"]
camDestroy _camera
hint format ["%1",_bankPitch]
exit

The 2 second delay is because this script is set to run at startup, so it's to let the functions get loaded and such.

Anyways, what I found is that the delay (set to 1 sec here) can be somewhere between 0.000001 and 0.0000001 (10-5 - 10-6). When it gets too low, the result (_bankPitch) just turns 0. So that kind of rules out function I guess.

But, the real problem is that when I remove the cameraEffect from the script, it returns 0 too. If I could remove this, then it would still be usefull to detect stance. Would just be a small minus that it had to be implemented into the script...

So, anyone got any suggestions how to solve this? It's kind of a bugger to have rewritten Dschulles pitch-function etc and then such a small detail fuck it all up :confused:

Btw, attached a "demo" of it all, with all functions and such in it...