Godot Version
v4.3
Question
I am trying to make a system where there are 2 modes for where the 4-way sprite is pointing. It uses the coordinates to determine the “direction” of the sprite. If the mode is “mouse”, the sprites change depending on the mouse position. If the mode is “key”, then the mouse is change depending on input. But when the coordinates coming from the “key” input code are put into the absf functions, an error will pop up, stating that Invalid access to property or key 'x' on a base object of type 'int'.
. I do not understand what must be put into the absf for the access to the property to be valid. Please help.
extends AnimatedSprite2D
@onready var anim = get_node("/root/FourWaySprite")
var direction = "south"
var direction_mode = "key"
var diffdir = 0
func _process(delta: float) -> void:
var diff: Vector2 = get_global_mouse_position() - global_position
if direction == "south":
anim.play("south")
if direction == "north":
anim.play("north")
if direction == "east":
anim.play("east")
if direction == "west":
anim.play("west")
if direction_mode == "mouse":
diffdir = diff
elif direction_mode == "key":
if Input.is_action_just_released("south"):
diffdir = Vector2(0,-1)
if Input.is_action_just_released("north"):
diffdir = Vector2(0,1)
if Input.is_action_just_released("east"):
diffdir = Vector2(-1,0)
if Input.is_action_just_released("west"):
diffdir = Vector2(1,0)
if absf(diffdir.x) > absf(diffdir.y):
# X is greater, east/west
if diffdir.x < 0.0:
direction = "west"
else:
direction = "east"
else:
# Y is greater or equal, north/south
if diffdir.y < 0.0:
direction = "north"
else:
direction = "south"
"""Use it only for debug reasons!"""
if Input.is_action_just_released("spacebar"):
print (str(diffdir) + " " + str(typeof(diffdir)) + " " + str(typeof(Vector2(0,0))))