Godot Version
4.2.2
Question
I seem to have an interesting problem. I have a test scene that has an enemy and a player. When the enemy is in range I want them to stop moving and shoot at the player.
My bullets seem to follow the player instead of going in a direct line. Now that is good for a different type of enemy, but I am trying to get them to go in a straight line.
this is what i have for creating the bullet
var projectile_instance = projectile.instantiate()
projectile_instance.position = self.global_position
projectile_instance.target_node_object = target_node_object
parent.add_child(projectile_instance)
this is the bullet instance script
extends CharacterBody2D
var speed = 100
var target_node_object
var max_speed = 200
# Called when the node enters the scene tree for the first time.
func _ready():
$Timer.start()
func _physics_process(delta):
velocity = position.direction_to(target_node_object.global_position) * speed
move_and_slide()
func _on_timer_timeout():
queue_free()
the problem is the bullet either follows the player as they move or just freezes in place so some reason if the player is close to the enemy
I’m looking for it to go in a direction and continue in that direction until it hits something, or the lifetime expires
Thanks