Godot Version
4.4
Question
it says that the line var direction := (transform.basis * Vector3(input_dir.z, 0, input_dir.x)).normalized()
is uncalable idk how to fix it
func input_dir(delta):
move_direction = Vector3()
var camera_basis = camera.get_global_transform_interpolated().basis
if Input.is_action_just_pressed("adelante"):
move_direction = camera_basis.z
elif Input.is_action_just_pressed("atras"):
move_direction += camera_basis.z
if Input.is_action_just_pressed("izquierda"):
move_direction = camera_basis.x
elif Input.is_action_just_pressed("atras"):
move_direction += camera_basis.x
move_direction.y = 0
move_direction= move_direction.normalized()
var direction := (transform.basis * Vector3(input_dir.z, 0, input_dir.x)).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)
You have a function named input_dir
, and apparently you also have a member variable (i.e. variable declared outside of this function) named input_dir
. Godot is likely confusing the variable with the function name.
Consider renaming either the function, or the variable input_dir
.
1 Like
@TokyoFunkScene I believe this is not the problem here, as you cannot define two members with the same, or Godot will show another error than the one that’s mentioned here.
@itamarstaroselski123 I think that on the line that’s causing the error, you don’t want to use input_dir
but move_direction
, like this!
var direction := (transform.basis * Vector3(move_direction.z, 0, move_direction.x)).normalized()
Because, as said already, input_dir
is a function, it doesn’t have any x
or z
variables. So when you write input_dir.x
, the code doesn’t know what to do, hence the error.
Let us know if that helps!
2 Likes
the code does not mark any more mistakes but the character still does not move
My guess is that you’re resetting move_direction
each time with that line:
move_direction = Vector3()
So you’re resetting the move direction, updating it with your inputs pressed down, applying it to velocity, then resetting it, and then your inputs and help down but not pressed so the code considers that there’s not movement.
Try removing the line resetting the value.
1 Like
that line is the one you quoted there?
1 Like
i took it off and it broke the code
Can you be a bit more specific? Do you have an error, or it the game just not working?
the player character does not move and just stays still floating
before it was working almost as i wanted it to work but i wanted the player character to move in relation to where he is looking at instead of the map
here is how its “working” now