Home   Help Search Login Register  

Author Topic: Getting the pitch angle of a helicopter  (Read 3245 times)

0 Members and 1 Guest are viewing this topic.

Offline Blanco

  • Former Staff
  • ****
Re:Getting the pitch angle of a helicopter
« Reply #15 on: 07 Apr 2005, 20:14:11 »
I just tried the script and I had a generic error in expression in cameraeffect1 setpos [(_xh + _xa),(_yh + _ya),_zh]

My mission setup :

- A AH1 named helo1
- A pilot named pilot1 (this moveindriver helo1 in the init)
- A gamelogic named cameraeffect1

I run the script without params : [] exec "nameofscript.sqs"

 
Search or search or search before you ask.

Chris330

  • Guest
Re:Getting the pitch angle of a helicopter
« Reply #16 on: 07 Apr 2005, 20:30:34 »
Quote
_camoffx = 5
_camoffy = -8
_helo = heli1
_pilot = pilot1
_cam1 = "camera" camcreate [0,0,0]
_cam1 cameraeffect ["internal", "back"]
_cam1 camsettarget cameraeffect1
_cam1 camsetrelpos [0,0,0]
_cam1 camcommit 0


#start
_cam1 camsettarget cameraeffect1
;Get hypotenuse of distance from pilot to helicopter
_x2 = getpos _pilot select 0
_x1 = getpos _helo select 0
_xdiff = _x2 - _x1
_y2 = getpos _pilot select 1
_y1 = getpos _helo select 1
_ydiff = _y2 - _y1
_l = sqrt((_xdiff^2) + (_ydiff^2))
;Get height difference from pilot to helicopter
_z2 = getpos _helo select 2
_z1 = getpos _pilot select 2
_zo = _z2 - _z1
;Find hypotenuse to get sin and cosine of angle
_h = sqrt((_l^2)+(_zo^2))
_sinangle = _zo/_h
_cosangle = _l/_h
;evaluate where camsetrelpos command should set the camera to for _camoffy
_e = (_sinangle) * (_camoffy)
_a = (_cosangle) * (_camoffy)
_heading = getdir _helo
_angle = 360 - _heading
_xa = (cos (_angle)) * _camoffx
_ya = (sin (_angle)) * _camoffx


;Get position co-ordinates of helicopter
_xh = getpos _helo select 0
_yh = getpos _helo select 1
_zh = getpos _helo select 2

;Position the object
cameraeffect1 setpos [(_xh + _xa),(_yh + _ya),_zh]
cameraeffect1 setdir _heading
_cam1 camsetrelpos [0,_a,-(_e)]
_cam1 camcommit 0
?camend : exit
goto "start"

Try it again mate. This should defo work as I have just tried it out. If not I will send you the demo mission ;)
« Last Edit: 07 Apr 2005, 20:38:11 by Chris330 »

Chris330

  • Guest
Re:Getting the pitch angle of a helicopter
« Reply #17 on: 07 Apr 2005, 20:33:07 »
Anyhoo I tried to use the height above sea level script and it just went mad. Maybe distance is not a good command to use. To be honest I think it's a pretty useless script anyway as it jerks to hell whenever you go over raised areas of land. Worth it for a bit of fun though ;D

UNN

  • Guest
Re:Getting the pitch angle of a helicopter
« Reply #18 on: 07 Apr 2005, 21:39:49 »
Quote
Because of varying differences between heli position and pilot position some helicopters do not work well with this (the camera has a tendency to point up in the air). Works great with the Apache, AH1, and Mi-17 though.

The differences should not be a problem as OFP will handle very small numbers. I still think using pilot position and heli position is the best way to get the pitch. You can use shulle's drop method or dedicated game logics, but that's over egging the pudding in my book. Pilot pos and height are fine and require no extra scripting\objects. The only problem is when you define roadway LOD's in the heli, like the Bas choppers. This will mess up the height values, again there are ways around it, but most choppers should work ok.

Quote
Correction!! I know why it jerks about. It is because of the difference between pilot and helicopter height values when they are over uneven terrain. This will be eliminated if I can get hold of the getpitch function

This can be fixed with a height above sea level function, you use it to level out the differences in the terrain. But you still need to calculate the angle between the two position.

There should be enough info in this:

http://homepages.gotadsl.co.uk/~gssoft/GameLogic.zip

You will have to change the functions to get the height from the pilot position and heli position. But all the basics are there.

Quote
When you use Vectorbossons function to correct this, it wil be called all the time and I think it will cause a crash to desktop.

Vectorbossons function will not cause a CTD, but a slight change will ensure the least amount of strain, on OFP:

Calling script:

Code: [Select]
_PitchOffset=_This Select 0

_Sensor="EmptyDetector" createVehicle [0,0,0]

#Loop

@(true)

_HPos=GetPos _Heli
_PPos=GetPos (Driver _Heli)

_HHeight=[GetPos _Heli,_Sensor] Call VB_NextHASL
_PHeight=[GetPos (Driver _Heli),_Sensor] Call VB_NextHASL

_Pitch=(_HHeight-_PHeight) ATan2 (Sqrt((((_HPos Select 0)-(_PPos Select 0))^2) + (((_HPos Select 1)-(_PPos Select 1))^2))))+_PitchOffset

;Camera code goes here

If (Alive _Heli) Then {goto "Loop"}

DeleteVehicle _Sensor

_PitchOffset - Is the angle between the pilot and the heli when the aircraft is parked on level terrain.

VB_NextHASL.sqf:

Code: [Select]
Private ["_currpos","_result","_sensor"];

_CurrPos=_This Select 0;
_Sensor=_This Select 1;

_Result=0;

_Sensor SetPos [0,0,0];
_Sensor SetPos [(_CurrPos Select 0),(_CurrPos Select 1),0];
_Result=(GetPos _Sensor ) select 2;

_Result

If it's still to jerky, then limit the amount the camera will move in any one frame. It might mean the camera trails a little behind the helicopters movment, but that could look ok and make it a bit more dynamic. I'm not sure exactly what effect your after but 456820's suggestion of using camsetrelpos, could be the best one to use if it fits? After all thats what the command was designed for.



Offline Flauta

  • Members
  • *
  • There is no knownledge, that is no power
    • Chek mi FLog
Re:Getting the pitch angle of a helicopter
« Reply #19 on: 08 Apr 2005, 01:48:29 »
well... maybe a n offtopic cuestion.. but.. there is a way to calculate the pich angle of an vehicle??
'Cause i hae a little "objet, desplasament" script... but there is no way I can do it to get the angle of the vehicle... (not the azimut one)

the scprit says something like these

Code: [Select]

_veh = this select 0
_cargo = this select 1
_xoff = this select 2
_Yoff = this select 3
_zoff = this select 4

#loop
_dir = dir _veh
_pos = getpos _veh
_x = _pos select 0 + _xoff
_y = _pos select 1 + _yoff
_z = _pos select 2 + _zoff
_cargo setpos [_x,_y,_z]
_cargo setdir _dir



sometingh like that... it is just a  fast writing, Asumming there is no internal error and no writing error, Can I set the Pich Angle of _cargo Relative to _veh??


Flauta

Chris330

  • Guest
Re:Getting the pitch angle of a helicopter
« Reply #20 on: 08 Apr 2005, 10:37:56 »
@UNN

Thanks for the detailed reply ;) To be honest I don't really understand the script you made but I can tell you that I wrote my own script to get absolute values and it ran like garbage. Can you tell me how to make a getpitch script like the one deschulle uses?

To be honest I doubt I will ever get it to work but it's maybe worth another try :)

UNN

  • Guest
Re:Getting the pitch angle of a helicopter
« Reply #21 on: 08 Apr 2005, 15:01:00 »
Quote
To be honest I don't really understand the script you made

You don't have to understand it yet, just copy and paste it. Once it's running it's not hard to work out what's happening.

Quote
Can you tell me how to make a getpitch script like the one deschulle uses?

Yes, but if you don't understand the above then it's probably a waste of both our time? As deschulle's drop method not only includes all of the above but also has six other scripts\functions that need explaining. Plus the additional layers of complexity you get with deschulle method, add their own problems.

So sorry, but I see no point explaining how to do something the hard way :)

Perhaps someone else can help by expanding on their ideas of how deschulle functions offer an advantage?

But I am happy to say I found my old copy of his functions. I tried to use them with the Inv44 Mortars a long time back, but they did not work. I think heli's should work, though.

Deschulle Pitch Bank Functions


@Flauta

Yes, just pass the vehicle to the script and change the variable _Heli, to the vehicle you pass in.
« Last Edit: 08 Apr 2005, 15:04:58 by UNN »

Chris330

  • Guest
Re:Getting the pitch angle of a helicopter
« Reply #22 on: 08 Apr 2005, 15:25:01 »
Yes, but if you don't understand the above then it's probably a waste of both our time? As deschulle's drop method not only includes all of the above but also has six other scripts\functions that need explaining. Plus the additional layers of complexity you get with deschulle method, add their own problems.

So sorry, but I see no point explaining how to do something the hard way :)

Maybe I am just too thick to understand it ;D I'm sure I will given time. I have an idea what your script does just haven't picked through it yet. Thanks for providing the download mate :D

Chris330

  • Guest
Re:Getting the pitch angle of a helicopter
« Reply #23 on: 08 Apr 2005, 19:58:54 »
As just posted at BI Forums:

IT REALLY WORKS 8)   Using dshculle's pitch function means the camera is stable and does not jump around. The helicopter moves up and down a bit when going over uneven terrain but I'm sure this is an OFP limitation and nothing to do with the script as I've had it happen when not using the pitch function too.   Anyone who is interested please get in touch and I will send you a demo mission :D

chris330330@hotmail.com  

Quote
 

_camoffx = 5
_camoffy = -8
_helo = heli1
_pilot = pilot1
_cam1 = "camera" camcreate [0,0,0]
_cam1 cameraeffect ["internal", "back"]
_cam1 camsettarget cameraeffect1
_cam1 camsetrelpos [0,0,0]
_cam1 camcommit 0



#start
_BankPitch = _helo call GetBankPitch
_Pitch = _BankPitch select 1
_sinangle = sin(_Pitch)
_cosangle = cos(_Pitch)

;evaluate where camsetrelpos command should set the camera to for _camoffy
_e = (_sinangle) * (_camoffy)
_a = (_cosangle) * (_camoffy)
_heading = getdir _helo
_angle = 360 - _heading
_xa = (cos (_angle)) * _camoffx
_ya = (sin (_angle)) * _camoffx


;Get position co-ordinates of helicopter
_xh = getpos _helo select 0
_yh = getpos _helo select 1
_zh = getpos _helo select 2

;Position the game logic
cameraeffect1 setpos [(_xh + _xa),(_yh + _ya),_zh]
cameraeffect1 setdir _heading
_cam1 camsetrelpos [0,_a,_e]
_cam1 camcommit 0
~0.00
1
?camend : exit
goto "start"

« Last Edit: 08 Apr 2005, 19:59:31 by Chris330 »

Chris330

  • Guest
Re:Getting the pitch angle of a helicopter
« Reply #24 on: 09 Apr 2005, 16:41:50 »
As just posted at BI Forums:

UPDATE****

I now have this script working perfectly, The helicopter no longer moves vertically on the screen even over uneven terrain. The reason it was moving was because of lateral changes in height above the ground between the helicopter and game logic unit the camera points at. But using a triangle and the distance command...I fixed it :D  Helicopter now stays rock solid on the left or right of the screen and the camera changes angle to match it's pitch. Basically it's like having a a real camera screwed to the side of a helicopter  

Thanks very much for all the help I will now submit this to OFPEC's editing depot  :D
« Last Edit: 09 Apr 2005, 17:57:17 by Chris330 »

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
Re:Getting the pitch angle of a helicopter
« Reply #25 on: 09 Apr 2005, 17:34:14 »
You don't have to understand it yet, just copy and paste it. Once it's running it's not hard to work out what's happening.Yes, but if you don't understand the above then it's probably a waste of both our time? As deschulle's drop method not only includes all of the above but also has six other scripts\functions that need explaining. Plus the additional layers of complexity you get with deschulle method, add their own problems.

So sorry, but I see no point explaining how to do something the hard way :)

Perhaps someone else can help by expanding on their ideas of how deschulle functions offer an advantage?

But I am happy to say I found my old copy of his functions. I tried to use them with the Inv44 Mortars a long time back, but they did not work. I think heli's should work, though.

Deschulle Pitch Bank Functions


@Flauta

Yes, just pass the vehicle to the script and change the variable _Heli, to the vehicle you pass in.

I LOVE YOU FOREVER!

:beat: *Gets Pitched* :beat:

Offline Blanco

  • Former Staff
  • ****
Re:Getting the pitch angle of a helicopter
« Reply #26 on: 09 Apr 2005, 18:01:46 »
I just tried it :)
NOW THAT IS A STABLE CAMERA!  :-*

Some suggestions :

I would prefer to create the gamelogics in the script so you don't have to place and name them in the editor. (and delete them afterwards when the script exit)

Can the same methode be used on my logiccam script?
Right now the camera is always pointed forward, is it possible to modify the script so you can run the script like this :

- 1) array with [x-y-z] camsetrelpos coords from the first gamelogic (cameraeffect1)  
- 2) array with [x-y-z] camsetrelpos coords from the second gamelogic(cameraeffect2)  
- 3) the vehiclename

[[-2,4,0],[6,7,1],heli1] exec "chase.sqs"
I hope you understand, this way you could follow a part from the vehicle like the nose or the landinggear...

Anyway, your script is marvelous work, take a break, you deserve it.  :)
 
 


« Last Edit: 09 Apr 2005, 18:42:40 by Blanco »
Search or search or search before you ask.

Chris330

  • Guest
Re:Getting the pitch angle of a helicopter
« Reply #27 on: 09 Apr 2005, 18:23:10 »
I am positively delighted you like the script :D I hope it will be of use to someone. I understand exactly what you meant and I think perhaps this is the next development I will make to it.

Put it this way...it can certainly be done ;) 8)