Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Bombing Run Level Help

I’m trying to understand and use vectors successfully. However I’m not exactly sure what to do with this level even though I know trig.

while(true) {
    var enemy = hero.findNearestEnemy();
    if(enemy) {
        // Find the vector of attack
        var ogreAttack = Vector.add(enemy.pos, hero.pos);
        // Use trigonometry to find the the angle in Radians!
        var degrees = Math.atan2(enemy.pos, hero.pos);
        // The answer must be in Degrees!
        var radians = degrees * (180 / Math.PI);
        // To convert Radians to Degrees multiply by (180 / Math.PI)
        // Say the angle!
1 Like

Ignore the last seven lines.

1 Like

You should start by changing this line:

To make a vector you need to use .subtract from them to you instead of .add.

Math.atan2 takes two arguments, and x argument and a y argument. The y argument goes first. What do you think you should use as the y and x?


Remember vectors have x and y properties. There’s a vector you haven’t used yet. :wink:

That should work,
P.S. put javascript after the first three ``` at the start of your code on the same line and it will format it as javascript (it makes the key words bold).
I’ve done it this time.


I finished the level with your help. However, I don’t understand the purpose of putting the vector in atan2. I know that for the inverse tangent it is opposite over adjacent. I don’t know how it did the level with just a coordinate point! Thanks for your help, I really appreciate it.

1 Like