Colobot Forum - International Colobot Community
Aim angle - Printable Version

+- Colobot Forum - International Colobot Community (https://colobot.info/forum)
+-- Forum: [Archive] New forum (2015-2019) (https://colobot.info/forum/forumdisplay.php?fid=76)
+--- Forum: Colobot: Gold Edition Basics (https://colobot.info/forum/forumdisplay.php?fid=58)
+---- Forum: General (https://colobot.info/forum/forumdisplay.php?fid=59)
+---- Thread: Aim angle (/showthread.php?tid=815)



Aim angle - clop1000 - 07-05-2016

My bad, i absolutely don't know a math and geometry.
Can someone advise me about how to determine an angle between a bot and a target.
Of course it's for Flying objects.
I will really appreciate your help if you can explain it step by step, cos i don't know what COS and SIN means. (i know words Big Grin, but don't know how it works)
 
And additional one - is there anyway to knowing is there a water or an another obstacle in front of you?
I am making manual driving bot (without using - goto, and even try don't use a move functions, only using motor())
 
 


BTW - it's such a cool game! Thx everyone for your work!


RE: Aim angle - krzys_h - 07-05-2016

For basics of trigonometry, all you need is these three definitions:
[Image: TrigonometryMnemonic_1000.gif]

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.


RE: Aim angle - clop1000 - 07-06-2016

Thx! Now i know the basics of trigonometry!)☺ I finally i understood meaning of Sin,and other unknown things ☺
Your post is fantastic.


RE: Aim angle - radioactivity - 07-06-2016

Colobot - entertains and teaches