# Incoming oscars! (That's military speak for ogres).
# You will need to calculate their angle of attack.
# Use that angle to command your Griffin Bombers!
while True:
enemy = hero.findNearestEnemy()
if enemy:
# Find the vector of attack
# Use trigonometry to find the the angle in Radians!
# The answer must be in Degrees!
# To convert Radians to Degrees multiply by (180 / Math.PI)
# Say the angle!

# Incoming oscars! (That's military speak for ogres).
# You will need to calculate their angle of attack.
# Use that angle to command your Griffin Bombers!
while True:
enemy = hero.findNearestEnemy()
if enemy:
# Find the vector of attack
vector.attack()
# Use trigonometry to find the the angle in Radians!
angle =
# The answer must be in Degrees!
# To convert Radians to Degrees multiply by (180 / Math.PI)
angle2 = 100 * angle
# Say the angle!
hero.say(angle2)

is this right and if not( I know its not) can u help?

# Incoming oscars! (That's military speak for ogres).
# You will need to calculate their angle of attack.
# Use that angle to command your Griffin Bombers!
while True:
enemy = hero.findNearestEnemy()
if enemy:
# Find the vector of attack
x = vector.x
y - vector.y
# Use trigonometry to find the the angle in Radians!
angle = math.atan2(y, x)
# The answer must be in Degrees!
# To convert Radians to Degrees multiply by (180 / Math.PI)
angle2 = 100 * angle
# Say the angle!
hero.say(angle2)

# Incoming oscars! (That's military speak for ogres).
# You will need to calculate their angle of attack.
# Use that angle to command your Griffin Bombers!
while True:
enemy = hero.findNearestEnemy()
if enemy:
# Find the vector of attack
x = Vector.x
y = Vector.y
# Use trigonometry to find the the angle in Radians!
angle = Math.atan2(y, x)
# The answer must be in Degrees!
# To convert Radians to Degrees multiply by (180 / Math.PI)
angle2 = 100 * angle
# Say the angle!
hero.say(angle2)

THE ONLY PROB HERE IS THEY RUN HORIZANTLY (MY GUYS)

I don’t now how to doo this level too.
Here is my code :

while True:
enemy = hero.findNearestEnemy()
if enemy:
# Find the vector of attack
vector=Vector.add(enemy.pos,hero.pos)
# Use trigonometry to find the the angle in Radians!
angle=Math.atan2(vector,enemy.pos)
# The answer must be in Degrees!
# To convert Radians to Degrees multiply by (180 / Math.PI)
angle=angle*(180/Math.PI)
# Say the angle!
hero.say(angle)

a library is a collection of precompiled routines that a program can use. Libraries are particularly useful for storing frequently used routines because you do not need to explicitly link them to every program that uses them.

So in the case of Math we have a structure like an object that has properties (attributes) and functions (methods).

We could have created this ourselves if it didn’t exist.

For instance

class MathLibrary:
PI = 3.14195
def __init__():
return True
def factorial(self, number):
factorialNumber = 1
while number > 0:
factorialNumber = factorialNumber * number
number -= 1
return factorialNumber
def power(self, number, power):
powerNumber = 1
while power > 0:
powerNumber = powerNumber * number
power -= 1
return powerNumber
Math2 = MathLibrary()
hero.say(Math2.PI)
hero.say(Math2.factorial(4) )
hero.say(Math2.power(-1,3) )

So basically think of the Math and Vector libraries as toolkits of already made code that you don’t have to create yourself. (imagine if you had to doTaylor approximationsto create the sin() function each time)

So the idea is to then understand what each function in the library does. If you don’t really understand them then we should write sample code to determine what is happening. This is where good documentation on each library function will be very helpful.

KHAN Academy gives a good refresher on Trigonometry and Arctan. If we don’t understand the math how can we know what to expect from running a Math function? So I encourage you to tough it out and review anything you are not 100% on.

What can we conclude from this output that Vector.add( <vector1>, <vector2> ) is doing?

And if we draw a line from our hero to the resulting point that was created (vector) from the above code where x=62, y=101, is that there we want our Griffin riders to attack?

That point location is somewhere off the screen to the right of the Hero isn’t it?

Lets start again. If we look at the hints we need to define a point from the Hero to the Enemy or a vector that starts at the hero and ends at the enemy. In the above diagram that would be up and to the left.

If we know that the x coordinates increase as you move from the left to the right, this would mean that we need a -x right? Because the enemy is to the left of our hero.

And we can observe that the enemy is above us and we know that the y values increase as you go up from the bottom. So this would mean a +y right?

So that means the vector that we want in the end is (-x,+y) from our hero.

[Challenge] Can you use the numbers returned from the above example in my last post and tell me what that new vector coordinates should be?

From this diagram we know that we want an angle > 90°. Working backward we can use a estimated guess for instance if we take 125° as 90° + 45° = 125° for a starting angle and then find the tangent of 125°.(convert to radians first)

Also notice that we are changing the zero point on the coordinates to the location of our Hero because that is what the Griffin Riders expect. They know our location and if we can give them an angle from our position that the Ogres are coming from, they will be able to setup their bombing run.

Can either of you tell me what the maximum and minimum angle in degrees ° that the griffin riders should accept? In other words the range of valid answers.

This is just the debug code to allow you to see what is happening.

Using this code, can you look at the vector library and determine which function might get you the vector from the hero pointing to the ogre? In other words the black arrow in the picture above.