Home   Help Search Login Register  

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

0 Members and 2 Guests are viewing this topic.

Chris330

  • Guest
Getting the pitch angle of a helicopter
« on: 06 Apr 2005, 13:52:56 »
Is this possible. I was thinking of scripting a camera script which points the camera at a game logic unit next to a helo. The camera then follows the game logic unit using a sciprt which updates its position every 0.01 seconds. The only problem is I would like to make it as if the camera were fixed to the helicopter so it matched its pitch angle. To do this I would need to be able to find out the helicopter's pitch angle so I could adjust the height at which the camera looked at the game logic unit thus matching the helo's pitch angle.

Soooo...

Is this possible? Or will I have to just stick with a script that ignores the helos pitch angle and keeps the cameras angle to the game logic unit constant ???
« Last Edit: 06 Apr 2005, 23:32:21 by Chris330 »

UNN

  • Guest
Re:Getting the pitch angle of a helicopter
« Reply #1 on: 06 Apr 2005, 14:08:17 »
Quote
To do this I would need to be able to find out the helicopter's pitch angle so I could adjust the height at which the camera looked at the game logic unit thus matching the helo's pitch angle.

Thats possible, the easiest way (as usual with OFP there is more than one way to skin a cat). Take the Height Above Sea Level (Vektorbosons function will do this, among others) of the Helicopter and It's Pilot, while placed on flat ground. Calculate the angle between the the heli and the pilots position and store this as an offset.

Then while in game, repeat the process but compare the result with the offset you recorded earlier. That will give you it's pitch (or bank) relative to the horizon, at any point in time.

This will work ok most of the time, a few things conspire to give you false readings for Height Above Sea Level. But assuming you wont want your camera to swing about to wildly, I'd just cap the values you use to move the camera about.

BTW What heli if any specific one, do you want to use this with?

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:Getting the pitch angle of a helicopter
« Reply #2 on: 06 Apr 2005, 14:52:26 »
I assume you are familiar with Blanco's Logiccam script in the Ed Depot.
Plenty of reviewed ArmA missions for you to play

Chris330

  • Guest
Re:Getting the pitch angle of a helicopter
« Reply #3 on: 06 Apr 2005, 16:50:34 »
I had never heard of it before but I just looked it up and looks great. Using two game logic units to get the pitch of it assume? A bit like the heli and pilot suggestion. A great idea. I'll try and make my own script using this for the hell of it and see how I get on.

I'll try it tonight and if one of you wouldn't mind testing it for me that would be great :D

Offline Blanco

  • Former Staff
  • ****
Re:Getting the pitch angle of a helicopter
« Reply #4 on: 06 Apr 2005, 16:57:41 »
My script is exactly what you're talking about Chris, but the camera is not fixed so the choppers pitch angle matches, but it works great with landvehicles.
Updating each 0.01 sec doesn't give you a smooth result, you'll need a constant loop. I even tried ~0.0000001, it still give you a bad headache...  :P
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.



 
   

Search or search or search before you ask.

Chris330

  • Guest
Re:Getting the pitch angle of a helicopter
« Reply #5 on: 06 Apr 2005, 19:36:20 »
WOW a reply from the man himself :D Cheers mate. I'm having a go at the script but I am thinking it will be quite hard to keep the game logic units in the same place with regard to the helicopter. I imagine it means lots of use of sine and cosine functions to do it as the helicopter will not always be facing directly north or south for example. I will have a go tonight and we'll see how I get on. I'm sure it could be done, even if it takes me a few months. It's more interesting than what I'm doing in work anyway :-X

Offline 456820

  • Contributing Member
  • **
Re:Getting the pitch angle of a helicopter
« Reply #6 on: 06 Apr 2005, 20:19:23 »
another simple well depends if you are using a game logic its a bit harder but with out
just use

Code: [Select]
# loop
_cam cameraeffect ["internal", "back"]
_cam camsettarget helicopter
_cam camsetrelpos [0,15,1]
_cam camcommit 0
~0
goto "loop"
? obj1 : goto "next part of script
# "next part of script"

whereas the camsettarget helicopter aims the cam at the chopper but i assume you already know that and the [0,15,1] means place the camera 0m left or right 15m back and 1m high you can adjust this to suit you

thats what i do when i need to attatch a cam to a vechile
i will explain alittle if you donr understand
it basically keeps looping that part until and objective variable is true or in this example obj1 then it goes to the next part of the script

Offline Blanco

  • Former Staff
  • ****
Re:Getting the pitch angle of a helicopter
« Reply #7 on: 06 Apr 2005, 20:36:43 »
Quote
means place the camera 0m left or right 15m back and 1m high you can adjust this to suit you

hmmm, this only true when the chopper is facing north.
To fix this so the camera stays always in the same relative position (regardless his direction), you'll need some cos-sin stuff.
Search or search or search before you ask.

Chris330

  • Guest
Re:Getting the pitch angle of a helicopter
« Reply #8 on: 06 Apr 2005, 22:29:42 »
hmmm, this only true when the chopper is facing north.
To fix this so the camera stays always in the same relative position (regardless his direction), you'll need some cos-sin stuff.


Which I have just done tonight :D It works a treat I use the cosine and sine functions of an offset x value to get the game logic's x and y position to keep it the same place with respect to the helicopter regardless of its heading and I update the script by pointing the camera at the game logic using a loop :D

The result is one nicely placed camera which follows the aircraft's heading all the way through at a fixed position with respect to the aircraft 8)

Now if I can just work out the pitch thing we'll be sorted ;)

Chris330

  • Guest
Re:Getting the pitch angle of a helicopter
« Reply #9 on: 06 Apr 2005, 23:24:49 »
Hmm. I'm unsure the pitch thing would work given how much the chopper moves around the screen in the vertical axis even with a 0.001 time delay loop. I have written a nice little demo mission Vietnam style with a huey if anyone wants me to e-mail it to them? Maybe I should submit the script to the editor's depot ??? ;)

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:Getting the pitch angle of a helicopter
« Reply #10 on: 06 Apr 2005, 23:31:46 »
Quote
Maybe I should submit the script to the editor's depot  
Of course you should!  :thumbsup:   Providing its been beta tested of course.

If in doubt, always submit.    Where's the harm?   Demo missions for scripts are strongly encouraged, although try and use default units if you possibly can.   It's a real chore to have to download an addon just to see if a script does what you need.
Plenty of reviewed ArmA missions for you to play

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
Re:Getting the pitch angle of a helicopter
« Reply #11 on: 06 Apr 2005, 23:54:58 »
Then, there is allways the dschulle functions:

http://www.ofpec.com/editors/funcref.php?filter_auth=dschulle

However, they seem to be un-downloadable. And they have been for ages and ages and ages and ages and ages and ages. *Hint for KtottE/HuBBa or whoever the PHP master is around here* ;)

I want those bloody functions! ;D

I've been wanting them for like 8 months now. :'(

:beat: *Gets Shot* :beat:
« Last Edit: 06 Apr 2005, 23:57:18 by dmakatra »

Chris330

  • Guest
Re:Getting the pitch angle of a helicopter
« Reply #12 on: 07 Apr 2005, 09:51:37 »
Thats possible, the easiest way (as usual with OFP there is more than one way to skin a cat). Take the Height Above Sea Level (Vektorbosons function will do this, among others) of the Helicopter and It's Pilot, while placed on flat ground. Calculate the angle between the the heli and the pilots position and store this as an offset.

Then while in game, repeat the process but compare the result with the offset you recorded earlier. That will give you it's pitch (or bank) relative to the horizon, at any point in time.

This will work ok most of the time, a few things conspire to give you false readings for Height Above Sea Level. But assuming you wont want your camera to swing about to wildly, I'd just cap the values you use to move the camera about.

BTW What heli if any specific one, do you want to use this with?

Thanks for the reply UNN. Sorry I overlooked this post. I will look into your solution. I am planning to use it witrh the SEB Nampack2 Hueys. I will however, make the demo mission using default units as macguba said ;)

Chris330

  • Guest
Re:Getting the pitch angle of a helicopter
« Reply #13 on: 07 Apr 2005, 19:08:45 »
I GOT IT TO WORK!!!!! Without the get pitch function. I have to say however I am using the difference in height between the pilot and helicopter because I don't have the get pitch function from deschulle yet. Hopefully that will be back online soon. If anyone's interested I will send them a demo mission via e-mail.

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.

If I can get the getpitch function then I will be able to massively update this script to work with any helicopter. Also due to OFP limitations sometimes the heli bobs up and down on the screen quite jerkily. This is an OFP flaw as there is nothing wrong with the code ;)

Here's the code:

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
~0.0001
?camend : exit
goto "start"


 8) 8)
« Last Edit: 07 Apr 2005, 19:15:03 by Chris330 »

Chris330

  • Guest
Re:Getting the pitch angle of a helicopter
« Reply #14 on: 07 Apr 2005, 19:19:11 »
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 ;)
« Last Edit: 07 Apr 2005, 19:19:32 by Chris330 »