Projectile speed problem

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By kiirii

I am working on a stg game, and I find the moving speed of the projectile is weird. The projectile moves faster when the player move in the y direction. But I want the speed keep constantly, how could I fix this?


Player movement code:

var velocity = Vector2(0,0)
var speed = 300
func _process(delta):
velocity.x = int(Input.is_action_pressed("move_right")) - int(Input.is_action_pressed("move_left"))
velocity.y = int(Input.is_action_pressed("move_down")) - int(Input.is_action_pressed("move_up"))

velocity = velocity.normalized()

global_position += velocity * speed * delta

Projectile movement code:

var velocity = Vector2(0, -1)
export var speed = 500

func _process(delta):
global_position += velocity * speed * delta

shooting speed problem

:bust_in_silhouette: Reply From: CassanovaWong

I usually add the speed of the unit firing the bullet to the bullet speed right before I add it to the scene. Especially if the unit is fast.

Also, I usually use Vector2.RIGHT rather than Vector2.UP like you did… Maybe, try Vector2.RIGHT, to see if using the x-axis changes it…

What node are you using for the projectile? Area2D?

oh, and maybe try using physics process instead of process.