Enemy projectile is not precisely fired at players position

Godot Version



<Hello. I would appreciate if you could teach me a reason why enemy’s projectile is not being fired at player’s position precisely.


func _shoot():
	var mage_ball = mageballScene.instantiate()
	mage_ball.global_position = $MageBallSpawner.global_position
	mage_ball.direction = global_position.direction_to(player.global_position)
extends CharacterBody2D

var speed := 125
var max_range := 300.0
var _travelled_distance = 0.0
#var direction = Vector2.ZERO

func _init():

func _physics_process(delta: float) -> void:
	var distance := speed * delta
	var motion : Vector2 = direction * speed * delta
	position += motion

show your player’s scene? does the player sprite and other nodes positioned at exactly the center?

yes. player is positioned exactly at the center.
If I put var direction = global_position.direction_to(player.global_position) inside projectile script, the projectile will follow player and comes at the center of player like homing missile. So yes, the player is exactly positioned at the center.

try change to this

mage_ball.direction = mage_ball.global_position.direction_to(player.global_position)
1 Like

Thank you very much. That fixed the problem. I really appreciate your help.

1 Like