Just like the title says every time I try to instance a projectile my project just freezes.
Here is my player code as well as my projectile code. Any help would be greatly appreciated!
Player
extends KinematicBody2D
#player movement variables
export (int) var speed = 700
var velocity = Vector2()
#varable for the magicshot
const MAGICSHOT = preload("res://wizard-character/magicshot.tscn")
func get_input():
velocity = Vector2()
if Input.is_action_pressed("Move_right"):
velocity.x += 1
if Input.is_action_pressed("Move_left"):
velocity.x -= 1
if Input.is_action_pressed("Move_down"):
velocity.y += 1
if Input.is_action_pressed("Move_up"):
velocity.y -= 1
velocity = velocity.normalized() * speed
if Input.is_action_pressed("Fire_mouse"):
shoot()
func shoot():
var m = MAGICSHOT.instance()
get_parent().add_child(m)
m.start_at(get_rotation(), get_position())
func _physics_process(delta):
get_input()
velocity = move_and_slide(velocity)
Project
extends Area2D
const speed = 100
var velocity = Vector2()
func _ready():
pass # Replace with function body.
func _physics_process(delta):
velocity.x = speed * delta
translate(velocity)
func _on_VisibilityNotifier2D_screen_exited():
queue_free()