• 2D
  • Top-Down Spawn Bullet Positioning Problem

I have a function that spawns a bullet, but somehow the start position of the bullet is wrong, please see the screenshot below:

Here's my current code: For the enemy for spawning the bullet


func _spawn_bullet():
	var bullet = bulletScene.instance()
	bullet.start($BulletSpawn.global_position, currentAngle, damage)
	owner.add_child(bullet)
	pass

and here's for the bullet:

extends KinematicBody2D

# properties
var bulletDamage = 0;
var targetPos = Vector2.ZERO
var velocity = Vector2()
var bulletAngle: float
var startPos

var bulletSpeed: int = 100

func start(origin: Vector2, angle: float, damage: int):
	startPos = origin
	bulletDamage = damage
	bulletAngle = angle
	velocity = Vector2(bulletSpeed, 0).rotated(bulletAngle)
	pass

func _ready():
	self.position = startPos
	pass

func _physics_process(delta):
	var collision = move_and_collide(velocity * delta)
	if collision:
		velocity = velocity.bounce(collision.normal)
		if collision.collider.has_method("hit"):
				collision.collider.hit()
	pass

func _on_VisibilityNotifier2D_screen_exited():
	queue_free()
	pass

I think the issue is that in _ready you are setting position to startpos instead of global_position, so it's applying the offset from the parent node(s) and that's causing it to be in the incorrect location. I would change the code in _ready so it sets the global_position and see if that fixes the issue.