Godot creating new instance sparks issues

Whenever I try to make a new instance of my bullet scene in Godot it would give me the typical error where I can’t use .new() or .instance() I figured it out and replaced it with .instantiate() and it worked… For the most part, no errors and no warning, but when I ran my game, the bullets appeared extremely small and almost invisible and moved very slow, I know the problem is not from my bullets because they work well when I don’t create them as a new scene.

I tried looking at stack overflow and even using ChatGPT but none of those sources helped.
here is my bullets code:

extends Area2D

var speed = -2400
var target = position
# Called every frame. 'delta' is the elapsed time since the previous frame.
func ready():
    rotation = get_global_mouse_position().angle_to_point(position)
    
func _physics_process(delta):
    position += transform.x * speed * delta
    

func _on_body_entered(body):
    if body.name == "Dummy":
        body.queue_free()
        queue_free()

**here is my gun’s code:
**

extends Sprite2D

var bullet = preload("res://scenes/bullet.tscn").instantiate()

# Called when the node enters the scene tree for the first time.
func _ready():
    pass # Replace with function body.

    
func shoot():
    add_child(bullet)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(_delta):
    rotation = get_global_mouse_position().angle_to_point(position)
    if Input.is_action_just_pressed("input_use_click"):
        shoot()

    
    


(EDITED BEYOND THIS POINT)
I fixed it appearing small and moving slow now my issue is that I can only create one bullet at a time.

  • Object appearing small and moving slow sounds like the camera is showing a large area (i.e. it is zoomed out).

    – 

  • I fixed that and it wasn’t a camera issue.

    – 

You are adding the bullets as children of the gun itself. This means that any transformation applied to the gun will be also applied to the bullets.

This can solved this by adding the bullets as a sibling instead of child. Changing add_child(bullet) to add_sibling(bullet) will do.

Leave a Comment