Ok so I use godot 4.7 and i keep getting this error and i dont know how to fix it
Invalid access to property or key 'anim' on a base object of type 'Node3D (AK-47.tscn::GDScript_pl6ux)'.
heres one of my weapons code
extends Node3D
@export var damage = 1.0
@onready var anim = $AnimationPlayer
@onready var shot_sound = $shot_sound
@onready var raycast = $RayCast3D
var can_shoot = false
func _process(sdelta: float) -> void:
if Input.is_action_just_pressed("Shoot") and can_shoot and not anim.is_playing():
print("something else wrong")
anim.play("shoot")
shot_sound.play()
if raycast.is_colliding():
if raycast.get_collider().is_in_group("enemy"):
raycast.get_collider().hp -= damage
func _on_animation_player_animation_finished(anim_name: StringName) -> void:
if anim_name == "shoot":
can_shoot = true
elif anim_name == "Equip":
can_shoot = true
visible = true
elif anim_name == "Unequip":
can_shoot = false
visible = false
and heres my players hand code(where theres apparently a problem
extends Node3D
var weapons = []
var selected_weapon = 0
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
for w in self.get_children():
weapons.append(w)
w.visible = false
w.anim.play("Unequip")
weapons[selected_weapon].visible = true
weapons[selected_weapon].anim.play("Equip")
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
if Input.is_action_just_pressed("Next_Weapon"):
weapon_change(1)
elif Input.is_action_just_pressed("Previous_Weapon"):
weapon_change(-1)
func weapon_change(dir):
weapons[selected_weapon].anim.play("Unequip")
selected_weapon += dir
if selected_weapon < 0:
selected_weapon += weapons.size()
elif selected_weapon >= weapons.size():
selected_weapon -= weapons.size()
weapons[selected_weapon].visible = true
weapons[selected_weapon].anim.play("Equip")
thanks