Godot Version
v4.2.2.stable.official [15073afe3]
Question
Hello, I’m having an issue with one of my in-game buttons, connected via node signals. One line in my code causes the game to break. For context, I have a platform that the player sits atop and moves forward when one of the buttons is held down, and backward when the other button is held down. The code is below. Remember, the forward button works perfectly well, but the backward button is messed up.
func forward(body):
marker.top_level = 1
translate(Vector3(-0.1,0,0))
player.execute_this_code = false
player.axis_lock_linear_x = 1
player.axis_lock_linear_z = 1
func forward_stop(body):
marker.top_level = 0
player.execute_this_code = true
player.axis_lock_linear_x = 0
player.axis_lock_linear_z = 0
func backward(body):
marker.top_level = 1
translate(Vector3(.1,0,0))
player.execute_this_code = false
player.axis_lock_linear_x = 1
player.axis_lock_linear_z = 1
func backward_stop(body):
marker.top_level = 0
player.execute_this_code = true
player.axis_lock_linear_x = 0
player.axis_lock_linear_z = 0
Under the function backward(), I have found that the line “translate(Vector3(.1,0,0))” is what’s causing the game to break. When the x value is negative in Vector3, the button works fine. Similarly, the button also works fine when the y or z value is changed in Vector3. However, when the x value is positive in Vector3, the game breaks. What’s happening here? What do I need to fix? Any help is appreciated.
Would it be possible to see the entire script, I am afraid that line is not what is causing you problems
It is called in signal upon the press of a button, which is interacted with using a raycast. The type is Node3D.
This is the entire script.
extends Node3D
@export var speed : Vector3 = Vector3(0,1,0)
@onready var player = $Player
@onready var marker = $Node3D/Marker3D
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
pass
func right(delta):
$Node3D.rotate_y(.01)
player.execute_this_code = false
player.axis_lock_linear_x = 1
player.axis_lock_linear_z = 1
func right_stop(body):
$Node3D.rotate_y(0)
player.execute_this_code = true
player.axis_lock_linear_x = 0
player.axis_lock_linear_z = 0
func forward(body):
marker.top_level = 1
translate(Vector3(-0.1,0,0))
player.execute_this_code = false
player.axis_lock_linear_x = 1
player.axis_lock_linear_z = 1
func forward_stop(body):
marker.top_level = 0
player.execute_this_code = true
player.axis_lock_linear_x = 0
player.axis_lock_linear_z = 0
func backward(body):
marker.top_level = 1
translate(Vector3(.1,0,0))
player.execute_this_code = false
player.axis_lock_linear_x = 1
player.axis_lock_linear_z = 1
func backward_stop(body):
marker.top_level = 0
player.execute_this_code = true
player.axis_lock_linear_x = 0
player.axis_lock_linear_z = 0
func left(delta):
$Node3D.rotate_y(-.01)
player.execute_this_code = false
player.axis_lock_linear_x = 1
player.axis_lock_linear_z = 1
func left_stop(body):
$Node3D.rotate_y(0)
player.execute_this_code = true
player.axis_lock_linear_x = 0
player.axis_lock_linear_z = 0
func _on_control_button_3_interacted(body):
pass # Replace with function body.
func _on_control_button_3_released(body):
pass # Replace with function body.
func _on_control_button_4_interacted(body):
pass # Replace with function body.
func _on_control_button_4_released(body):
pass # Replace with function body.
func _on_control_button_interacted(body):
pass # Replace with function body.
func _on_control_button_released(body):
pass # Replace with function body.
func _on_control_button_2_interacted(body):
pass # Replace with function body.
func _on_control_button_2_released(body):
pass # Replace with function body.
I don’t know how it’s not that line considering everything else works and if I change that line then it works as well. I’m willing to look anywhere for a solution at this point, though. Thanks
Sorry for the poor description. When I press the forward button, the platform moves forward, but when I press the backward button, the game freezes and I am no longer able to move or interact. Thank you
When I press the backward button, the game freezes and I have to press F8 to exit
Hello, I use C#, but when I look at the float documentation of GD, nowhere do they use the “.1” notation for float. Have you tried “0.1” instead? Sorry, it’s a silly takes .
Sorry about that, I’ve tried it both ways and it has the same result.
1 Like
Try to press pause when the game freezes. I guess it’s infinity loop or something blocked main thread.
This is very helpful, thank you for the video. But it is baffling me, how this happens. I am convinced that the problem is somewhere else. How about you try dublicating the Forward button for the backward one, maybe something will change?
Pressing pause and then unpause doesn’t seem to fix the issue.
Duplicating the forward button is how the button was originally made. I’ve even tried creating another button from scratch to no avail. It’s baffling me, too. I’m completely lost at this point, lol. I’ve tested it some more, though. Any value greater than one or less than zero seems to work in the x position, but any value in between causes the game to freeze like in the video. Maybe it’s a problem with the engine itself? Idk
What if we temporary make so if for example you press space, it activates the backwards function. To see if there is a problem with the button or the function
Press the button, then pause the game. Check the editor to find which line is blocking thread.
Could you capture the “script” tab and debugger panel when game is paused?