Home   Help Search Login Register  

Author Topic: Angle mesurement script!  (Read 2918 times)

0 Members and 2 Guests are viewing this topic.

Robinhansen

  • Guest
Angle mesurement script!
« on: 14 Jun 2005, 22:24:35 »
I need a script to mesure the angle of a gunbarrel. Lets say a M109 or 2S1 are aming at a target at 1000m, then I need a script to mesure the angle of the gun at that distance...
 :D


Offline RujiK

  • Members
  • *
  • KoKo Puh-Fizzles!
Re:Angle mesurement script!
« Reply #1 on: 15 Jun 2005, 17:38:38 »
Do you mean angle or direction? Angle would be tilted to one side while direction would be the way your unit is facing.
If you wanted direction you could just do getdir shooter. For angle its much harder.
I like your approach, lets see your departure.
Download the New Flashlight Script!

Bluelikeu

  • Guest
Re:Angle mesurement script!
« Reply #2 on: 15 Jun 2005, 18:38:02 »
I think that he is talking about the angle of depression.
If so, I'm not sure how this can be accomplished since, I believe, you cannot get any values relating to the gun, its position, or other values.

Grendel

  • Guest
Re:Angle mesurement script!
« Reply #3 on: 16 Jun 2005, 00:47:55 »
Whew! thats a tough one....The most plausable method that I've heard of, involves adding a new ammo to the config of the vehicle for a 'invisible no-dammage" shell, forcing the vehicle to target and fire that round, and use trig to find out the angle....

If you are trying to do an artillery script using real rounds fired and such, you can save yourself about a month of work and most of your hair by downloading Chain Of Command's Unified Artillery (they came up with a fuzzy logic node AI thing to work out trajectories).

Or if you insist on doing it the hard way, another method would be to use an invisible target addon, and setpos it to make the gun elevate to a desired angle you have previously worked out through trial and error (Ive done this to make enemy snipers shoot accurately over inordinately long ranges)....

-Grendel

Robinhansen

  • Guest
Re:Angle mesurement script!
« Reply #4 on: 16 Jun 2005, 10:14:18 »
I'm aware of CoC, and they ROCK!!

What I'm looking for is the angle and not direction. I was trying to mesure the angle of the BM-21 from OUR WEAPON by using the method showed in the attached file...

I cant make the DoWatch work, so if anyone can solve it, I do need the script... 8)

Offline Sefe

  • OFPEC Patron
  • Former Staff
  • ****
Re:Angle mesurement script!
« Reply #5 on: 16 Jun 2005, 10:29:05 »
Obtaining the horizontal angle of a gunbarrel is not difficult. The gun points where the unit looks to. Just get the direction of the unit with getDir and if that doesn't work out, try to get the direction of the unit's gunner. I've done this so I know it's possible.

Or do you need to measure the gun elevation? If that's what you want, you did not express yourself precisely. In this case it's hard to measure the elevation but you can manipulate it. Use camCreate to create an object to aim at (a PipeBomb will do well for that purpose), make sure the unit sees the object with reveal and then let the unit aim at the object. If you put up the object high in the air the gun will elevate to that object. The altitude of the object is easily calculated: altitude = distance * sin elevationAngle. However this is an approximate elevation angle, since the gun will elevate to hit the target which means that the shell has to take a ballistic trajectory. Make sure your gun fires projectiles of high velocity. The higher the velocity, the closer the elevation angle will be to the target angle.

If you know the target the gun aims at (and the gun fires projectiles of very high velocity and little air friction), you can calculate the approximate gun elevation like this:

elevationAngle = arcsin ((heightOfTarget - heightOfFiringUnit) / distance)

If your projectiles take a ballistic trajectory due to their low velocity, you need to calculate the gun elevation angle from the distance of the target, the difference in altitude of target and firing unit, the muzzle velocity of the projectile and the air friction of the projectile. I don't have the formula in my head and most likely this will require a lot of trial and error. The muzzle velocity and the air friction of the projectile can be obtained from the config.cpp file of the firing unit.

Unfortunately I don't know what you want to do since you didn't express yourself precisely enough. Another interpretation of what you want could be that you want to determine the bearing of a target relative to the compass direction your gun is pointing to. In this case: there is an easy solition: Use the atan2 operator to determine the bearing from the relative position of the object. Here is an extract of my guided missile script where I calculate the compass direction of the target relative to the missile (not using atan2 but atan, which is the more complex solution but works just as well):
_DeltaX = (_TargetPos Select 0) - (_MissilePos Select 0)
_DeltaY = (_TargetPos Select 1) - (_MissilePos Select 1)
? (_DeltaY == 0) && (_DeltaX >= 0) : _TargetAngle = 90
? (_DeltaY == 0) && (_DeltaX < 0) : _TargetAngle = 270
? _DeltaY > 0 : _TargetAngle = ATan (_DeltaX / _DeltaY)
? _DeltaY < 0 : _TargetAngle = ATan (_DeltaX / _DeltaY) + 180
? _TargetAngle < 0 : _TargetAngle = _TargetAngle + 360
« Last Edit: 16 Jun 2005, 10:58:11 by Sefe »

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re:Angle mesurement script!
« Reply #6 on: 16 Jun 2005, 13:49:04 »
An alternate solution, if the unit is going to fire anyway, is to use a "fired" eventhandler to catch the projectile.  You can then calculate the required angles from the projectile's initial velocity.
« Last Edit: 16 Jun 2005, 13:49:56 by Mr.Peanut »
urp!

Bluelikeu

  • Guest
Re:Angle mesurement script!
« Reply #7 on: 16 Jun 2005, 15:13:41 »
An alternate solution, if the unit is going to fire anyway, is to use a "fired" eventhandler to catch the projectile.  You can then calculate the required angles from the projectile's initial velocity.

Woah, thats cool, I'm still not sure what the velocity values mean. I can manipulate them in scripts and get what I want but I can't seem to figure out wth the velocity values are for.

Thanks,
Bluelikeu

Robinhansen

  • Guest
Re:Angle mesurement script!
« Reply #8 on: 16 Jun 2005, 16:53:21 »
Actually I was trying to make the script attached below fit the BM-21, and make it able to fire up to 8000m
« Last Edit: 16 Jun 2005, 16:54:24 by Robinhansen »

Bluelikeu

  • Guest
Re:Angle mesurement script!
« Reply #9 on: 16 Jun 2005, 20:19:15 »
Lol, we've all been jipped. What exactly seems to be the problem with compatibility?

Robinhansen

  • Guest
Re:Angle mesurement script!
« Reply #10 on: 26 Jun 2005, 19:38:50 »
I found this description in the editors depot but it seems to be to complicated to me. I don't quite get what the description says, so...  :-\

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Angle mesurement script!
« Reply #11 on: 26 Jun 2005, 22:24:26 »
Okay, I think you need to clarify...

Do you want to find the elevation of the barrel, or do you want to be able to set the elevation of the barrel?

In other words, do you want to be able to find what direction the player/AI is pointing their barrel at any one point in time? This is not possible, AFAIK. As mentioned, you have to wait until they fire (or force them to), because you can then find out the direction the shell is travelling (and thus the direction the barrel is pointing).

Or, do you want to be able to tell the AI to point their barrel at a specific elevation? This is incredibly easy, and only requires that you use the "dowatch" command (or is it "dotarget"?). And if you are telling them where to point their barrel, then you can easily figure out their angle of elevation with some simple geometry.

HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Robinhansen

  • Guest
Re:Angle mesurement script!
« Reply #12 on: 29 Jun 2005, 22:34:11 »
Quote
Or, do you want to be able to tell the AI to point their barrel at a specific elevation? This is incredibly easy, and only requires that you use the "dowatch" command (or is it "dotarget"?). And if you are telling them where to point their barrel, then you can easily figure out their angle of elevation with some simple geometry.

Exactly what I want but what sounds to be very easy does'nt work for me.

My Rocketlauncher (Artillery) are supposed to target a jeep (Target)

initfield:
Code: [Select]
Artillery doWatch [Getpos Target select 0,Getpos Target select 1,Height]
and gives me the angle at every 50m between 1000m to 8000m

but I only gets an errormesage... ??? Do not ask me why I write THIS sentence in the initfield - I just followed the description in the Artillery Tutorial in the attached "makeartilery.zip"
« Last Edit: 29 Jun 2005, 22:37:24 by Robinhansen »

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Angle mesurement script!
« Reply #13 on: 30 Jun 2005, 01:23:46 »
What exactly is the error message? And are the variables "artillery" and "target" defined? Meaning, have you named those units on the map?
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

hermano

  • Guest
Re:Angle mesurement script!
« Reply #14 on: 30 Jun 2005, 15:22:54 »
Also check if the you set a value for the "Height" variable - or just use getpos Target select 2 - although that could mean that the ai targets at the target directly, I suppose you will have to find the right height to get a hit if that happens, maybe dotarget would solve the height problem.

UNN

  • Guest
Re:Angle mesurement script!
« Reply #15 on: 01 Jul 2005, 14:59:52 »
I noticed your using FDF mortars? These are configured differently to say SEB Nam or Inv44. Thats probably not the cause of your error message, but it might explain why you are having so much trouble.

Inv44 mortars work as follows:

0 degrees Horizontal
90 degrees Vertical

FDF goes the other way round:

0 degrees Vertical
90 degress Horizontal

You could always use this:

Mortar Addon (FDF)

And type this in it's in it field:

Code: [Select]
[Group This,Target] Call FCU_GroupFireTarget
Shameless plug I know, but it's easier than typing out the triganometry required to do the same thing for your script  :P

I will, if you want me to :) As I would always encourage people to do there own thing, just depends how much time you want to spend doing it?
« Last Edit: 01 Jul 2005, 15:02:32 by UNN »

Offline RobinHansenDK

  • Members
  • *
  • I'm a llama!
Re:Angle mesurement script!
« Reply #16 on: 04 Jul 2005, 23:13:04 »
Even though the username is not quite the same it's still me -->accedently logged me self out and forgot my password (...just hate when such thing happens! >:()

So:
Actualy forget about the mortars. The error mentioned is here shown on the attached .jpg.

Im trying to find out the fireparameters of the BM-21 (Our weapon). If I replace the FDF-mortars with the BM-21 it elevates just like mortars, so I'm pretty sure that the script needs some different parameters for the BM-21

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Angle mesurement script!
« Reply #17 on: 04 Jul 2005, 23:23:40 »
Are you positive that you have defined the variables Artillery, Target, and Height? ???
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline RobinHansenDK

  • Members
  • *
  • I'm a llama!
Re:Angle mesurement script!
« Reply #18 on: 05 Jul 2005, 00:02:10 »
Not at all...

Rocketlauncher --> "Artillery"
Jeep --> "Target"
Height --> "???"

"Height" is the problem! Remember I just copyed the line from the tutorial...

Offline RobinHansenDK

  • Members
  • *
  • I'm a llama!
Re:Angle mesurement script!
« Reply #19 on: 05 Jul 2005, 00:41:26 »
I'm pretty sure that when this script works with rocketlaunchers, cannons, tanks etc. then my problems will be solved... :D

http://www.ofpec.com/yabbse/index.php?board=27;action=display;threadid=22918
« Last Edit: 05 Jul 2005, 00:43:01 by RobinHansenDK »

UNN

  • Guest
Re:Angle mesurement script!
« Reply #20 on: 05 Jul 2005, 10:56:26 »
Well for the time being just experiment with the height value to see how it works:

Code: [Select]
Artillery DoWatch [GetPos _Target Select 0,GetPos _Target Select 1,1000]
If the target is 1000 meters away, setting the height to 1000 should give you a angle of 45 degrees.

Offline RobinHansenDK

  • Members
  • *
  • I'm a llama!
Re:Angle mesurement script!
« Reply #21 on: 05 Jul 2005, 14:08:44 »
Now I got rid of the error message...but now for the 1.000.000$ question! How do I get the AI to fire? I've tried the command way --> F2 - 3 - 3 (Fire) but the moron won't follow orders... ;)

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Angle mesurement script!
« Reply #22 on: 06 Jul 2005, 10:05:59 »
Okay, I think we are talking in circles here... a lack of communication about what exactly you want, what you currently have, and what you know.

Try this. Make yourself a script called "fire.sqs". Inside of that script, write the following:

Code: [Select]
arty dowatch [getpos target select 0, getpos target select 1, 100]
~2
arty fire (weapons arty select 0)
exit

Next, name the vehicle that you want to be firing "arty". Then, name the target you want it to fire at "target".

Use this line in a trigger's "on activation" field in order to run that script:

[] exec "fire.sqs"

Now, try running the script in your mission. Watch how the launched missle/shell whatever lands. Then adjust the number 100 in the script above, until you can get the weapon to hit properly. If the arty is shooting past the target, lower the number. If it isn't shooting far enough, then raise the number. After enough trial and error you will be able to get it to hit.

One note: this will only work when the artillery and the target stay in the exact same positions! If they move, then you will have to find a new value (instead of 100 or whatever you ended up with). If you want to make a script that will work no matter where the target or shooter are, then it will be more complicated, but first start out by getting the above script to work.



PS: The script of mine you linked to doesn't work with vehicles. Once I finish that script, I'll make a version specifically for vehicles.
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!