#godot default script template for CharacterBody3D doesn't work?

1 messages · Page 1 of 1 (latest)

barren widget
#

so im following a tutorial and the default template for the character and when i try it the character doesn't move.

im using godot 4.3
this is my code

extends CharacterBody3D


const SPEED = 5.0
const JUMP_VELOCITY = 4.5


func _physics_process(delta: float) -> void:
    # Add the gravity.
    if not is_on_floor():
        velocity += get_gravity() * delta

    # Handle jump.
    if Input.is_action_just_pressed("ui_accept") and is_on_floor():
        velocity.y = JUMP_VELOCITY

    # Get the input direction and handle the movement/deceleration.
    # As good practice, you should replace UI actions with custom gameplay actions.
    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)

    move_and_slide()
proper condor
#
  • Are you using the arrow keys or somehow changed the default bindings?
  • Is there any other object in the level to use as reference for the movement?
barren widget
proper condor
#

Just, anywhere. To know if it is running at all.

barren widget
#

nothing appears to be happening

proper condor
# barren widget nothing appears to be happening

The breakpoint should be on a line with code.
if nothing happens, the code is not running.

Which means that either you set the tree to be paused in some script, or this script is not the one in your node.

barren widget
#

so it hit a breakpoint which means the code is running

proper condor
#

Couple things to check:

  • Is the SPEED high enough to notice a difference?
  • What happens if you print the result of input_dir every frame?
barren widget
#

i set the speed way higher to no difference. but printer input_dir gives me this

(-1, 0)
(-1, 0)
(-1, 0)
(-1, 0)
(-1, 0)
(-1, 0)
(-1, 0)
(-1, 0)
(-1, 0)
(-1, 0)
(-1, 0)
(-1, 0)
(-1, 0)
(-1, 0)
(-1, 0)
(-1, 0)
(-1, 0)
(-1, 0)
(-1, 0)
(-1, 0)
(-1, 0)
(0, 0)
(0, 0)
(0, 0)
(1, 0)
(1, 0)
(1, 0)
(1, 0)
(1, 0)
(1, 0)
(0.707107, -0.707107)
(0.707107, -0.707107)
(0.707107, -0.707107)
(0.707107, -0.707107)
(0.707107, -0.707107)
(0.707107, -0.707107)
(0.707107, -0.707107)
(0.707107, -0.707107)
(0, -1)
(-0.707107, -0.707107)
(-0.707107, -0.707107)
(-0.707107, -0.707107)
(-0.707107, -0.707107)
(-0.707107, -0.707107)
(-0.707107, -0.707107)
(-0.707107, -0.707107)
(-1, 0)
(-1, 0)
(-1, 0)
(-1, 0)
#

*those were when I was pressing the keys

proper condor
#

Ah, sorry. You should be printing the velocity.

Add a print() to the if and else. And make them distinct to know which one is running.

barren widget
#

so doing that I get this

If is being called, (0, 0, -99)
If is being called, (0, 0, -99)
If is being called, (0, 0, -99)
If is being called, (0, 0, -99)
If is being called, (0, 0, -99)
If is being called, (-70.00358, 0, -70.00358)
If is being called, (-70.00358, 0, -70.00358)
If is being called, (-70.00358, 0, -70.00358)
Else is being called, (0, 0, -99)
Else is being called, (0, 0, 0)
If is being called, (0, 0, 0)
If is being called, (99, 0, 0)
If is being called, (99, 0, 0)
If is being called, (99, 0, 0)
If is being called, (99, 0, 0)
If is being called, (70.00358, 0, 70.00358)
If is being called, (70.00358, 0, 70.00358)
If is being called, (70.00358, 0, 70.00358)
If is being called, (70.00358, 0, 70.00358)
Else is being called, (99, 0, 0)
Else is being called, (0, 0, 0)
Else is being called, (0, 0, 0)
Else is being called, (0, 0, 0)
Else is being called, (0, 0, 0)
If is being called, (0, 0, 0)
Else is being called, (0, 0, -99)

the numbers after is the velocity vector3

proper condor
#

Then it is moving.
Only thing i can think of is that the camera is not in the character in question. As in, you have 2 cameras.

#

Generally, the last camera to be added takes precedence.

barren widget
#

this is the entire scene hierarchy with one camera. and this is the camera properties

barren widget
#

apparently the reason it wasn't moving was because it was on a cube and not a plane?