07-05-2016, 04:27 PM
For basics of trigonometry, all you need is these three definitions:
To calculate the angle, we'll use sin(). For our purposes:
h is the distance in 3D between objects. h = distance(this.position, other.position)
o is difference in height between objects. o = other.position.z - this.position.z
Additionally you need to know that while sin takes an angle as parameter and returns a proportion, there is an inverse function that takes a proportion and returns an angle, called arcus sinus (asin()).
So the basic targetting code is:
(be aware that I wrote this without checking in game so there may be an error somewhere)
For detecting obstacles in front, you can use radar() with the extended syntax (see SatCom for more info). To detect water you need topo() function and some more trigonometry.
To calculate the angle, we'll use sin(). For our purposes:
h is the distance in 3D between objects. h = distance(this.position, other.position)
o is difference in height between objects. o = other.position.z - this.position.z
Additionally you need to know that while sin takes an angle as parameter and returns a proportion, there is an inverse function that takes a proportion and returns an angle, called arcus sinus (asin()).
So the basic targetting code is:
Code:
float h = distance(this.position, other.position);
float o = other.position.z - this.position.z;
float angle = asin(o/h);
aim(angle);
(be aware that I wrote this without checking in game so there may be an error somewhere)
For detecting obstacles in front, you can use radar() with the extended syntax (see SatCom for more info). To detect water you need topo() function and some more trigonometry.