SelinaDev / Godot-Roguelike-Tutorial

Yet Another Roguelike Tutorial in Godot
MIT License
78 stars 10 forks source link

Fireball effect does not match reticle aiming #9

Closed pkillthetoy closed 7 months ago

pkillthetoy commented 7 months ago

The reticle for aiming the fireball draws a rectangle around the selected tile. But the fireball consumable uses euclidean distance instead of the max-of-abs distance used by enemies to determine if they're within range 1 of the player (I forget the name).

Because of this, increasing fireball radius and then trying to clip an enemy with the corner of it will fail to affect them.

SelinaDev commented 7 months ago

You are right, I messed up there. I'll have a look soon what parts of the code use the distance calculation. I think the only other part is the lightning scroll. I don't know if using Chebyshev distance should be used for the lightning scroll, as it might make judging the distance unintuitive for players. However, I do like the idea to fully committing to Chebyshev instead of Euclidian.

ghost commented 7 months ago

does this fix work as intended? it nukes all orcs in my screen. with radius being 3 and having identical code for fireball scroll.

ghost commented 7 months ago

Used the fireballs i had on me without moving from my spawn tile. killed the orcs outside my vision and the radius. the red dot thingies are corpses. image

SelinaDev commented 7 months ago

First of all I really like what you've done with the visuals! Unfortunately though, I cannot reproduce the bug you're describing. Using the code from part 9 I am now able to affect orcs in the corner of the targeting square, but orcs outside it remain unaffected. Does the same happen with the lightning scroll? Could you maybe use a breakpoint to check what happens in the distance calculation / fireball scroll?

ghost commented 7 months ago

Hmm, alright, so it is on my end. makes sense, but i had to make sure.

also: Thanks! was going more for a surface with forests vibe, and used this tutorial as a small starting point with godot. thank you for your hardwork.

SelinaDev commented 7 months ago

I am terribly sorry @Devengel, I did not test properly/enough. You were right (at least three quarters right). I forgot to take the absolute values of the relative vector. That means that it works properly in one quadrant, but results in negative distances in the other four. Incidentally, when I tried it out the enemies outside the fireball range happened to be in the right quadrant, which is why it looked to me as if everything worked as it should.

The proper distance calculation looks as follows:

func distance(other_position: Vector2i) -> int:
    var relative: Vector2i = other_position - grid_position
    return maxi(abs(relative.x), abs(relative.y))

I'll soon upload the corrected version.

ghost commented 7 months ago

No need to apologize and thank you for your work as always