# Can rangers and Wizards miss there shots

**URL:** <https://discourse.codecombat.com/t/can-rangers-and-wizards-miss-there-shots/25236>\
**Category:** Bugs\
**Created:** [November 5, 2020, 1:51pm UTC](https://discourse.codecombat.com/t/can-rangers-and-wizards-miss-there-shots/25236 "2020-11-05T13:51:13Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [November 5, 2020, 1:51pm UTC](https://discourse.codecombat.com/t/can-rangers-and-wizards-miss-there-shots/25236/1 "2020-11-05T13:51:13Z")

</div>

Some times Pender, Nalfar, Ritic and Senick. Miss there shots why does this happen

---

<div class="post-metadata">

**Author:** ![riticmaster9087](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/riticmaster9087/32/15515_2.png) [@riticmaster9087](https://discourse.codecombat.com/u/riticmaster9087)\
**Post date:** [November 5, 2020, 1:54pm UTC](https://discourse.codecombat.com/t/can-rangers-and-wizards-miss-there-shots/25236/2 "2020-11-05T13:54:04Z")

</div>

can you send me a screenshot?

---

<div class="post-metadata">

**Author:** ![Alexbrand](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Alexbrand](https://discourse.codecombat.com/u/Alexbrand)\
**Post date:** [November 5, 2020, 2:23pm UTC](https://discourse.codecombat.com/t/can-rangers-and-wizards-miss-there-shots/25236/3 "2020-11-05T14:23:08Z")

</div>

> [@Sir Robin Bravely Ran Away - looked for a more elegant answer and received a class in using Vector](https://discourse.codecombat.com/t/sir-robin-bravely-ran-away-looked-for-a-more-elegant-answer-and-received-a-class-in-using-vector/5140/5):
>
> This is exactly what happens in horror-movies. You run away from the monster/killer/… and end up in a corner. Another way to dodge enemies is to move not directly away from them but 90° to that line: targetPos = Vector.subtract(self.pos, enemy.pos) targetPos = Vector.rotate(1.5708) # PI/2 = 1.5708 rad = 90° self.move(targetPos) This is especially helpful for dodging projectiles as they move in a straight line, but should work against not so fast enemies as well. You don’t have to use exactly …

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [November 5, 2020, 2:26pm UTC](https://discourse.codecombat.com/t/can-rangers-and-wizards-miss-there-shots/25236/4 "2020-11-05T14:26:13Z")

</div>

here is Pender

 ![Screen Shot 2020-11-05 at 9.19.00 AM](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/b/2/b2d88e5d9467bc425a221bb5a7a93bbe357176ee.jpeg)

See that dark patch down there right next to the red dot that is where Pender shot and missed.

This is Senick

 ![Screen Shot 2020-11-05 at 9.21.07 AM](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/8/6/861fe9535359f1aff8727c027aa8a54c8b60d7ea.jpeg)

there is a dart above that is above the living enemy that is Senicks shot

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [November 5, 2020, 5:44pm UTC](https://discourse.codecombat.com/t/can-rangers-and-wizards-miss-there-shots/25236/5 "2020-11-05T17:44:11Z")

</div>

If rangers and wizards can miss their shots then people would loose the level because of that.

---

<div class="post-metadata">

**Author:** ![Alexbrand](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Alexbrand](https://discourse.codecombat.com/u/Alexbrand)\
**Post date:** [November 5, 2020, 6:21pm UTC](https://discourse.codecombat.com/t/can-rangers-and-wizards-miss-there-shots/25236/6 "2020-11-05T18:21:07Z")

</div>

> [@milton.jinich](#):
>
> Miss there shots why does this happen

As far as I know heroes can miss if:

- they shoot the target that is stands still and after shot starts to move or
- they shoot the target that moved to certain direction (with constant velocity) and changed it (or velocity) after shot.

> [@milton.jinich](#):
>
> If rangers and wizards can miss their shots then people would loose the level because of that.

Single-player levels are made in such a way that one miss doesn’t make a big difference, aren’t they?  
And multiplayer ones are supposed to be of win/lose matter)

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [November 5, 2020, 6:38pm UTC](https://discourse.codecombat.com/t/can-rangers-and-wizards-miss-there-shots/25236/7 "2020-11-05T18:38:25Z")

</div>

Not necessarily true @Alexbrand I lost a Fine Mint because Pender missed the Peons

---

<div class="post-metadata">

**Author:** ![Alexbrand](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Alexbrand](https://discourse.codecombat.com/u/Alexbrand)\
**Post date:** [November 5, 2020, 6:56pm UTC](https://discourse.codecombat.com/t/can-rangers-and-wizards-miss-there-shots/25236/8 "2020-11-05T18:56:03Z")

</div>

Did you miss all the shots?  
Maybe you can modify your function attackEnemy()? F.e. you can shoot enemy while his HP more than 0 maybe.

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [November 5, 2020, 7:03pm UTC](https://discourse.codecombat.com/t/can-rangers-and-wizards-miss-there-shots/25236/9 "2020-11-05T19:03:58Z")

</div>

It senick just missed like 3 times pender forget about it

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [November 5, 2020, 7:13pm UTC](https://discourse.codecombat.com/t/can-rangers-and-wizards-miss-there-shots/25236/10 "2020-11-05T19:13:26Z")

</div>

I think just some types of hero’s just have lousy shots

---

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [November 5, 2020, 8:34pm UTC](https://discourse.codecombat.com/t/can-rangers-and-wizards-miss-there-shots/25236/11 "2020-11-05T20:34:12Z")

</div>

milton.jinich : pender forget about it  
Alexbrand : while his HP more than 0  
/click to see **animation** /

 ![pender-small](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/0/7/07fd2841add9f44bba2e85c0323d88a2228f5a5f.gif)  
Yes, Alex - it works, but it’s an ugly solution.

---

<div class="post-metadata">

**Author:** ![Alexbrand](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Alexbrand](https://discourse.codecombat.com/u/Alexbrand)\
**Post date:** [November 5, 2020, 8:49pm UTC](https://discourse.codecombat.com/t/can-rangers-and-wizards-miss-there-shots/25236/12 "2020-11-05T20:49:48Z")

</div>

> [@xython](#):
>
> Yes, Alex - it works, but it’s an ugly solution.

Fie!)Many of my code tricks can be described the same way) It doesn’t hinder them to work though) Oh, I see the problem, animation helps, thanks.  
To be serious, it was the first thing came to my mind. I haven’t much experience with Pender, but I think distanceTo(enemy) might help also. And some kind of spells maybe (smth to slow the enemies down).

---

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [November 5, 2020, 9:24pm UTC](https://discourse.codecombat.com/t/can-rangers-and-wizards-miss-there-shots/25236/13 "2020-11-05T21:24:19Z")

</div>

Something that always perplexed me, why this piece of code doesn’t work consistently:

```python
    var enemy = hero.findNearestEnemy();
    while (enemy && enemy.health >0 ) {
        console.log(enemy.id + " target: " + enemy.target);
        hero.attack(enemy);
    }

```

output: ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/5/6/56ed5abfa6c5fd0ccaaa8772ce0eb573c69d4ed5.png)

![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/f/c/fcd1ed6c7024cb359ebffe4f406c77bc1c6c3bd2.png)

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [November 5, 2020, 9:59pm UTC](https://discourse.codecombat.com/t/can-rangers-and-wizards-miss-there-shots/25236/14 "2020-11-05T21:59:17Z")

</div>

Thanks guys I’ll try to put these strategies to use

---

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [November 5, 2020, 10:14pm UTC](https://discourse.codecombat.com/t/can-rangers-and-wizards-miss-there-shots/25236/15 "2020-11-05T22:14:20Z")

</div>

You have Boss Star III , so you are at least in the end of mountain, so maybe you always try to use the “best” weapon available . Don’t nuke the poor peons, the default code will be OK for a wizard with the weakest Enchanted Stick.

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [November 6, 2020, 12:14pm UTC](https://discourse.codecombat.com/t/can-rangers-and-wizards-miss-there-shots/25236/16 "2020-11-06T12:14:17Z")

</div>

I am not in the mountain I just went to the level that gave me boss star III

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [November 6, 2020, 12:14pm UTC](https://discourse.codecombat.com/t/can-rangers-and-wizards-miss-there-shots/25236/17 "2020-11-06T12:14:34Z")

</div>

I am at the very first levels of the mountain

---

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [November 8, 2020, 9:59pm UTC](https://discourse.codecombat.com/t/can-rangers-and-wizards-miss-there-shots/25236/18 "2020-11-08T21:59:15Z")

</div>

In this case i’m using:  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/5/7/57b0487cfa06dd7e9323d75082f92eeb6c438b00.png) ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/0/2/0292217015b866a7da9e558c1b418cab36213382.png)

```python
var param = 3/4;
var n = 0;
function attackEnemy() {
    var coin = hero.findNearestItem();
    var enemy = hero.findNearestEnemy();
    if (enemy && coin){
      var x = (enemy.pos.x + coin.pos.x)*param;
      var y = (enemy.pos.y + coin.pos.y)*param;        
      while(hero.distanceTo(Vector(x,y))> 0)
        hero.move(Vector(x,y));
    }    
    while (enemy && ++n <= 2 ) {
        hero.attack(enemy);
        console.log(enemy.id + " health:" + enemy.health + " attack #" + n );
    }    
    n = 0;
}

```

The wizard is with vine staff  
I was hoping the code will work with n\<=1, but this is not the case - the peon is still alive.

```python
  while (enemy && ++n <= 2 ) // n<= 1 fails;

```

n\<= 3 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/3/e/3eb40520a4b7e639faf36a47917e518957e3e93f.png)  
animation with n \<= 2 ( **click to see** )

 ![fine-mint](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/8/9/891ea342347145cefc09234ceb3314dcc30851a0.gif)

If i replace the wizard with a ranger and a similar DPS weapon , **the ranger needs only one shot** to defeat the enemy.  
Only the weakest wizard staff succeeds to have the task done in one shot.  
**Why are the wizard weapons so inaccurate?**

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [November 9, 2020, 10:00am UTC](https://discourse.codecombat.com/t/can-rangers-and-wizards-miss-there-shots/25236/19 "2020-11-09T10:00:17Z")

</div>

Wow, I just wanted to say how beautiful that code is! Going onto the peons course is such a good idea.  
About this code not working:

> [@xython](#):
>
> ```javascript
> var enemy = hero.findNearestEnemy();
> while (enemy && enemy.health >0 ) {
> console.log(enemy.id + " target: " + enemy.target);
> hero.attack(enemy);
> }
> 
> ```

I may be missing the point of this code, but I’ve used enemy.target quite a lot and I think the reason this code isn’t working is because enemy.target is an object, not a string like enemy.id. So I think it would be like running:

```javascript
console.log(enemy.id + " target: " + enemy)

```

enemy.target can only be another unit as far as I know. I tried the following code on “A fine mint” and the if never ran, whereas on “Woodland cleaver” I get this result (Screenshot below ⬇)

```javascript
while (true) {
    var enemy = hero.findNearestEnemy();
    if (enemy && enemy.target) {
        var target = enemy.target;
        var x = Math.round(target.pos.x);
        x = String(x);
        var y = Math.round(target.pos.y);
        y = String(y);
        var id = target.id;
        hero.say(enemy.id + "'s target's position is: " + x + y);
    }
}

```

 ![Screen Shot 2020-11-09 at 09.55.02](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/a/5/a5d08ff09d8dfc3b89c92e4bc1ada8011aadf6ba.jpeg)  
28, 17 is of course Illia’s position. This would definitely work with summoned troops as well.  
So in conclusion, it seems enemy.target only includes other units, and never items. You can find the pos of the enemy’s target and also it’s .id (although I haven’t used that in the screenshot). There also doesn’t seem to be a .targetPos function for enemies, which I think would be quite cool.  
Danny  
P.S. If you want console and String to look blue and cool (as well as having var and other commands in bold) you can put ```javascript at the top of the code. (I’ll always thank @ Shurutsue for that. Unfortunately no longer active…)

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [November 9, 2020, 11:06am UTC](https://discourse.codecombat.com/t/can-rangers-and-wizards-miss-there-shots/25236/20 "2020-11-09T11:06:22Z")

</div>

I used the Precision Rifle and the Vine Staff. So I have to use the enchanted Stick to get the Job done

[Next page](https://discourse.codecombat.com/t/can-rangers-and-wizards-miss-there-shots/25236.md?page=2)
