[SOLVED] Reflective Shield - Python

The problem that I am facing is with dealing damage to Nalfar. I tried all the numbers from 0.1 through 0.8 for “z” in the reflect method, no use. I successfully reflect it towards him, but zero damage.

Link to level (sub)
Here is my code:

# Use hero.reflect() to reflect back Nalfar's projectiles!

while True:
    enemy = hero.findNearestEnemy()
    missile = hero.findEnemyMissiles()[0]
    direction = Vector.normalize(Vector.subtract(enemy.pos, hero.pos))
    if missile and hero.distanceTo(missile) < 5:
        hero.reflect(Vector(direction.x, direction.y, 0.5))

sadly this level is not loading for me :frowning:

okay … maybe you can try using Illia if you have her, because the level is made to use her reflect ability … and thanks for trying to help

1 Like

Don’t need to find the nearest enemy. Find all missiles, it should return an array. Use a for loop to run through the missiles array and check is a missile exists before reflecting it. You don’t need to check the distance.

1 Like

But what should I fill in the reflect?

That’s the code for now:

while True:
    missiles = hero.findEnemyMissiles()
    for missile in missiles:
        if missile:
            hero.reflect(Vector(x, y, z))
hero.reflect(Vector(direction.x, direction.y, 1.9))

It’s what you had except the z value is different.

It sends it too high. more than 0.8 is too high, less that 0.2 is too low, what’s in between hits Nalfar but does no damage

while True:
    enemy = hero.findNearestEnemy()
    missiles = hero.findEnemyMissiles()
    direction = Vector.normalize(Vector.subtract(enemy.pos, hero.pos))
    for missile in missiles:
        if missile:
            hero.reflect(Vector(direction.x, direction.y, 1.9))

(nearest enemy is to find direction, which is for reflect, i dunno what else to do)

You have this already but you need to add this line of code right before the reflect statement:

direction = Vector.subtract(missile.pos, hero.pos)

You don’t need to use enemy in your code, because enemy is irrelevant. For reflect reflect direction.x and direction.y and experiment with z values.

1 Like

Ah okay, will do (20chars)

1 Like

It worked, i didn’t need to change the z value from 1.9
Thank you @abc

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.