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

Reflective Shield feedback

I started reflective shield and started by writing this code, which succeeds in reflecting the projectiles, but it sends them much to high (screenshot 1).

while True:
    nalfar = hero.findNearestEnemy()
    dir = Vector.subtract(nalfar.pos, hero.pos)
    dir = Vector.normalize(dir)
    hero.reflect(dir)

screenshot 1:
Screen Shot 2021-07-03 at 12.12.58
Then, I tried to do change the dir.z property in the same way as it’s done in the code example, and it threw up this error (screenshot 2):

while True:
    nalfar = hero.findNearestEnemy()
    dir = Vector.subtract(nalfar.pos, hero.pos)
    dir = Vector.normalize(dir)
    dir.z = 0.3
    hero.reflect(dir)

screenshot 2:


I managed to complete the level by entering the z value in a dictionary with x and y as dir.x and dir.y. Also the z value does require fine tuning to 0.1 increments to get the right angle to deal damage to Nalfar.
The reflect ability does obviously work, but I think the reflect ability documentation should be changed so that the code doesn’t cause an error.
Does anyone else see this in this level, or any other levels when using relfect()?

1 Like

For vectors, there is also a z(height) along with x and y. You need to specify a z direction.

The example is just one way you can reflect a projectile. It’s on you to modify the code so it works. If the answer was in the example code, it wouldn’t be interesting.

No, but that’s the problem. It’s not one way you can reflect a projectile because it doesn’t work. Obviously I wouldn’t expect it to be the answer to the level, but I would expect it to give, as you said, an example of something that would reflect something in some way.

My bad, I misinterpreted your post. I’ll take a look and change the example code.

Hi, Deadpool198 how do you enter the z value in a dictionary with x and y as dir.x and dir.y because i am stuck on the level too, thanks

Welcome to the forum! :smiley:
We hope you have a lovely, enjoyable, and fun time here on the CodeCombat Discourse.
This forum is a homely place, where you can share ideas, share made levels, report bugs, get help on code, and so much more!
We hope you review this topic for all the rules of the forum!
Thanks and enjoy your time here!!!
:partying_face:

Hi and welcome! I think you need to make a new topic. You need help on the level. Deadpool was giving feedback. Thanks and I hope you pass this level!

Hi, i already make a new topic and RangerGrant9307 already gave me some advice but i cannot complete this level, thanks.

1 Like