Godot Version 4.3.stable
I have a very odd problem that passes my (fairly basic) debug check. I’m using the base code for CharacterBody3D (with three main changes: removed the notes, moved move_and_slide to _process, and added a separate controller for turning the player). The ui_left and ui_right elements, while still recognized, aren’t moving the player left and right respectively. They used to work when the player and my test scene were one and the same, but after I gave the player it’s own scene, it stopped working. I hadn’t tested it much, though I did notice it, as I was working on a cam controller. Which took a bit.
Further testing with this little bugger:
print(str(x) + "; (" + str(Input.is_action_pressed("ui_left")) + ", " + str(Input.is_action_pressed("ui_right")) + "); " + str(velocity))
Tells me that something is wrong with this:
if direction:`
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
…I’m relatively new to Godot though, so that’s as much as I know. I think it’s this because str(velocity) always gives (0, 0, 0) when only pressing left or right, even though the game does register that they are being pressed. Forward and backward work as normal.
extends CharacterBody3D
const SPEED = 5.0
const JUMP_VELOCITY = 4.5
var x = 0
var s = 0.005
func _physics_process(delta: float) -> void:
if not is_on_floor():
velocity += get_gravity() * delta
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY`
var input_dir := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
if ((Input.is_action_pressed("ui_left") or Input.is_action_pressed("ui_right")) or x != 0) and not Input.is_action_pressed("ui_page_up"):
print(str(x) + "; (" + str(Input.is_action_pressed("ui_left")) + ", " + str(Input.is_action_pressed("ui_right")) + "); " + str(velocity))
Debugger for player movement. There’s a seperate debugger for the camera, so I have an off button for both of them, though the cam off button is page down.
func _process(delta: float) -> void:
move_and_slide()
Forward and backward lag when this is in _physics_process, sometimes only working when turning
func _unhandled_input(event):
if event is InputEventMouseMotion:
if get_tree().has_group("turn_active"):
rotate_y(-event.relative.x * s)
x = -event.relative.x * s
else:
x = 0
Cam control has a free x axis, so there is a group that says when the cam has maxed out the min or max x of the cam.