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.