Home   Help Search Login Register  

Author Topic: Degree detection  (Read 925 times)

0 Members and 1 Guest are viewing this topic.

klavan

  • Guest
Degree detection
« on: 26 Jan 2005, 12:50:14 »
This is my first attemp with this kind of calculation. So I you would take a look at this code and give your opinion I thank you.

Code: [Select]
;....by the position of the target to the angle of acquisition of the Torpedo's targeting system wich I set to 120 degrees....
_source = _torp
_target = sub
_sourcedir = getdir _torp
_angle = ((getpos _target select 0) - (getpos _source select 0)) atan2 ((getpos _target select 1) - (getpos _source select 1))

?_degree
_difference = _angle - _sourcedir
?_difference >= -20 : _Angleperc = 20
?_difference <= 20 : _Angleperc = 20
?_difference >= -40 : _Angleperc = 15
?_difference <= 40 : _Angleperc = 15
?_difference >= -60 : _Angleperc = 10
?_difference <= 60 : _Angleperc = 15

;....wich results in:
_RoughPerc = ToHit + (_DistPerc + _Angleperc)
« Last Edit: 26 Jan 2005, 12:52:16 by klavan »

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:Degree detection
« Reply #1 on: 27 Jan 2005, 02:17:27 »
just use getdir
you don't need to use the trig to get angles

Offline Raptorsaurus

  • Editors Depot Staff
  • *****
Re:Degree detection
« Reply #2 on: 27 Jan 2005, 03:52:42 »
Quote
just use getdir
you don't need to use the trig to get angles


I think he is trying to calculate the relative direction to the target (not the absolute direction or its heading, but the bearing to the target).  Is this correct klavan?

I have a whole slew of functions for doing directional calculations.  Everything from calculating the direction of movement (things do not always move in the exact direction their nose is pointing), to functions that calculate incremental direction changes (so, for instance, in a script you can have a projectile realistically turn toward the target).  I've been meaning to submit many of these to the function library, but just have not gotten arround to it.  Anyway, I'll attach a folder of just my directional functions and you can look through these and see if any of them will help with what you are trying to do in this script.  The right function can reduce your script to about 3 or 4 lines!

The attached folder is a .zip of all such function, including a few writen by other people.
« Last Edit: 27 Jan 2005, 03:53:11 by Raptorsaurus »

klavan

  • Guest
Re:Degree detection
« Reply #3 on: 27 Jan 2005, 12:17:43 »
You're right Raptosaurus, this should influence the overall % the torpedo hit the target, simulating the time spended in maneuvering for a better hooking by the target acqusition system of the weapon launched.
I've downloaded your attached files. I'll try 'em and then I'll report the results.
Many thanks.

klavan

  • Guest
Re:Degree detection
« Reply #4 on: 27 Jan 2005, 13:45:48 »
Ok, this is the newest version:

 
Code: [Select]
;....by the position of the target to the angle of acquisition of the Torpedo's targeting system wich I set to 120 degrees....
_source = _torp
_target = sub
_sourcedir = getdir _torp
_degree = ((getpos _target select 0) - (getpos _source select 0)) atan2 ((getpos _target select 1) - (getpos _source select 1))
?_degree < 0:_degree = _degree + 360

;The better the alignement of the Torpedo respect the target the higher the chance to hit
;This simulate the time spended by the Torpedo in maneuvering for a proper alignement
_degree = _degree - _sourcedir
?_degree >= 61 : _Angleperc = 16 ; hint format ["più %1, risulta %2, atteso 16", _degree, _Angleperc]
?_degree <= 40 : _Angleperc = 18 ; hint format ["più %1, risulta %2, atteso 18", _degree, _Angleperc]
?_degree <= 20 : _Angleperc = 20 ; hint format ["più %1, risulta %2, atteso 20", _degree, _Angleperc]

All seem to work fine, now.
For the moment, I've decided not to put any function file as this script is part of a suite and my intention is to take the amount of files as low as possible.
However, Raptosaurus, your files gave me the solution to my problem.
Thanks a lot for your help. :thumbsup: