Godot Version
4.2
Question
Trying to use position in a statement causes the statement to never run?
I have an idea of another way i could tackle this but I’ve run into this issue before where despite my variables matching what im checking for in my if statements, they never run.
entire script for transparancy
extends Camera3D
var tween
var left = "left"
var right = "right"
var back = "back"
var state = "neutral"
var isHeld = false
func _process(_delta):
# inputs
if Input.is_action_just_pressed(left) and state == "neutral":
state = "left"
isHeld = true
tween = get_tree().create_tween()
tween.tween_property(self, "position", Vector3(-1,0,0), .2)
elif Input.is_action_just_pressed(right) and state == "neutral":
state = "right"
isHeld = true
tween = get_tree().create_tween()
tween.tween_property(self, "position", Vector3(1,0,0), .2)
elif Input.is_action_just_pressed(back) and state == "neutral":
state = "back"
isHeld = true
tween = get_tree().create_tween()
tween.tween_property(self, "position", Vector3(0,0,1), .2)
# releases
if Input.is_action_just_released(left):
isHeld = false
elif Input.is_action_just_released(right):
isHeld = false
elif Input.is_action_just_released(back):
isHeld = false
if isHeld == false:
tween = get_tree().create_tween()
tween.tween_property(self, "position", Vector3(0,0,0), .2)
if global_position == Vector3(0,0,0) and isHeld == false:
state = "neutral"
prints(global_position, isHeld, state)