Godot 4.2.1
Why im getting this error?
attempt to call function “shoot” in base “null instance” on a null instance
extends CharacterBody2D
var MOVE_SPEED = 100
@onready var ray_cast_2d = $RayCast2D
@onready var player : CharacterBody2D = get_tree().get_first_node_in_group(“player”)
@onready var range_enemy = $Range_enemy
var dead = false
func _ready():
range_enemy = $Range_enemy
func _physics_process(_delta):
if dead:
return
var dir_to_player = global_position.direction_to(player.global_position)
update_movement(dir_to_player)
update_rotation(dir_to_player)
check_collision_with_player()
if range_enemy != null:
check_collision_for_shooting()
func update_movement(dir_to_player):
velocity = dir_to_player * MOVE_SPEED
move_and_slide()
func update_rotation(dir_to_player):
global_rotation = dir_to_player.angle() + PI/2.0
func check_collision_with_player():
if is_colliding_with_player():
player.kill()
range_enemy.shoot()
func check_collision_for_shooting():
if is_colliding_with_player() and range_enemy != null:
range_enemy.shoot()
func is_colliding_with_player() → bool:
return ray_cast_2d.is_colliding() and ray_cast_2d.get_collider() == player
func kill():
if dead:
return
dead = true
$DeathSound.play()
$Graphics/Dead.show()
$Graphics/Alive.hide()
$CollisionShape2D.disabled = true
z_index = -1
func shoot():
$MuzzleFlash.show()
$MuzzleFlash/Timer.start()
$ShootSound.play()