I have a problem with cannon script godot-4

I dont know why but the bullet doesnt spawn in it`s position correctly

projectile script



extends Area2D
var travelled = 0

func _physics_process(delta) :
	const SPEED = 500
	const RANGE = 1200
	
	global_position.x += -1 * SPEED * delta
	travelled += 1
	if travelled == RANGE:
		queue_free()
	


func _on_body_entered(body) :
	queue_free()
	
	if body.has_method("damage_taken"):
		body.damage_taken()

###Cannon script



extends StaticBody2D

func shoot():
	const BULLET = preload("res://scenes/projectile.tscn")
	var bullet_spawn = BULLET.instantiate()
	bullet_spawn.global_position.x = %point.global_position.x
	##bullet_spawn.global_rotation.x = %point.global_rotation.x
	%point.add_child(bullet_spawn)


func _on_timer_timeout() -> void:
	shoot()


Just remove this line. When a child added to a node, it gets that node position as it’s position so you did not need to change it again.

1 Like

Thanks that worked properly

1 Like