Hi ! I'm actually having troubles figuring out an issue I have with a skill that can be a melee aoe around the player, or a projectile if a condition's true.
It goes well for first enemy, but when it's focusing a second one, it derps and seems to go in the opposite y axis ? Not very good with vectors yet.
Here are the codes used in this portion :
match selected_skill :
if min_enemy != null:
if reap_cd == false:
reap_cd = true
is_attacking = true
var reap_instance = reap_scene.instance()
reap_instance.damage = atk
if boosted == true:
reap_instance.damage = atk*2
reap_instance.pen = true
reap_instance.transform = $Muzzle.global_transform
reap_instance.projectile = true
reap_instance.position = position
reap_instance.hit_radius = PlayerData.character_skills_data["Shade"]["Reap"]["radius"]
stamina -= PlayerData.character_skills_data["Shade"]["Reap"]["cost"]
reap_cd = false
is_attacking = false
This one's for launching the function getting the closest enemy as well as setting up and instancing the skill.
var min_dist = 99999
var enemies = get_tree().get_nodes_in_group("enemies")
for enemy in enemies:
var dist = pos.position.distance_to(enemy.position)
if (dist < min_dist):
min_dist = dist
min_enemy = enemy
if enemy != null:
min_enemy = null
This one returns the closest enemy to the function that called it.
var projectile = false
var speed = 250
var damaged = 
var pen = false
$CollisionShape2D.shape.radius = hit_radius
if projectile == true:
position += transform.y * speed * delta
if body.is_in_group("enemies") and !damaged.has(body):
if pen == false:
And this one is the script on the skill.
I can't figure out how to fix this issue, so I'd take any help and tips you guys could give me.
Here's an additional video is it helps understand how the projectile is acting : https://youtu.be/ttm3h8KfoF8