Godot Version
4.1.1
Question
I have some code, but when it runs, it produces two errors.
Here’s the code:
extends Node2D
@export var transformation = Transform2D()
@export var rotation_speed = 1000
@onready var pickcollision
var limb
var rotating = false # Degrees per step
var total_rotation = 0 # Total rotation so far
var beardy
var picksprite
var tilemap
var small_movement = Vector2(0.1, 0.1)
# Called when the node enters the scene tree for the first time.
func _ready():
limb = $"."
limb.visible = false
# Load the scene containing the TileMap
var scene = load("res://Scenes/Themine.tscn")
# Instance the scene to access its nodes
var scene_instance = scene.instantiate()
# Find the TileMap node within the scene
tilemap = find_tilemap_node(scene_instance)
pickcollision = $"."
emit_signal("pickcollision_ready")
pickcollision.set_deferred("disabled", true)
picksprite = $"../AnimatedSprite2D3"
func _process(delta):
limb = $".."
pickcollision = $"."
beardy = $"../../../CollisionPolygon2D"
transformation.origin = pickcollision.global_position
##var collide
# Check for key press
if Input.is_action_pressed("ui_accept"):
CollisionManagement._on_body_exited(tilemap, delta)
# Check for key release
else:
rotating = false
pickcollision.set_deferred("disabled", true)
limb.visible = false
pickcollision.rotation = 0
func rotate_limb(delta):
if rotating:
# Rotate the limb
limb.rotate(deg_to_rad(rotation_speed) * delta)
# Update total rotation
total_rotation += rotation_speed
# Check if total rotation reaches 360 degrees
if total_rotation >= 360:
total_rotation = 0
rotating = false
func find_tilemap_node(node):
# Recursive function to find the TileMap node within the scene
if node is TileMap:
return node
The errors are
Can't change the visibility of the main window
(likely referring to limb.visible)
and
Node not found: "../../../CollisionPolygon2D" (relative to "/root/PickaxeSwing").
Any help would be appreciated.
Thanks.