Projectile speed affected by direction

Godot Version

4.4

Question

Hello. I’m currently trying to develop an horizontal schump to learn the basics.

I have an issue with speed projectile. The ennemy shoot in the direction of the player. The projectile speed seems affected by the position of the player.

If i’m at the left of ennemy the projectile seems more slow
If i’m at the right of the ennemy, the projectile seems more fast.

My code :

Bullet.gd

extends Area2D

@export var speed: float = 300  
var direction: Vector2 = Vector2.ZERO

func _process(delta):
    if direction != Vector2.ZERO:
        position += direction * speed * delta

func set_direction(target_position: Vector2):
    direction = (target_position - global_position).normalized()

Function shoot of the ennemy :

func shoot():
    if player:
        var bullet = bullet_scene.instantiate() 
        bullet.global_position = global_position
        bullet.set_direction(player.global_position)
        get_parent().add_child(bullet)

How i can disconnected the speed from the position to shoot ?

PS : the indent is correct in my code but broken here.

Use ``` lines before and after the code, then it will be formatted correctly.

Anyway, what is the parent of your bullet scene? If it’s something that moves, that movement will also affect the child nodes.

Maybe you can change position to global_position here.

global_position instead of position not solve the issue.

The bullet scene is instanciated in world2d :

World2d never move

The code seems correct, can you print out the speed to see if it’s actually different?

I have printed the speed, she is constant, i think it’s a pure optic effect…
nevermind, i have desactivated the shoot if the player are after the ennemy.

thanks for your help :slight_smile:

1 Like