Isometric projectile

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

Move this piece to ready:

velocity = position.direction_to(target_node_object.global_position) * speed

So it is set once and never updates.

Otherwise you are changing the direction each time the physics process it called.

LOL, i am such a idiot. Of course, the physics process updates every tick so the velocity updates its location each time.

haha, still laughing at myself…

Thanks for the info :slight_smile:

1 Like

Haha, dont worry about it. We all do it from time to time, just glad I happened to see it quickly and could help.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.