i got these 2 outputs Input
Direction: ( 0, 0)
Velocity: (0, 0, 0)

extends CharacterBody3D

const SPEED = 5.0
const SPRINT_SPEED = 10.0  # Adjust as needed
const CROUCH_SPEED = 2.0   # Adjust as needed
const JUMP_VELOCITY = 4.5  # Increase the jump velocity for a more noticeable effect

# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")

# Crouch variables
var is_crouching = false
var original_scale = Vector3(1, 1, 1)
var crouched_scale = Vector3(1, 0.5, 1)

func _ready():
	original_scale = scale

func _physics_process(delta):
	# Add the gravity.
	if not is_on_floor():
		velocity.y -= gravity * delta

	# Handle jump.
	if is_on_floor() and Input.is_action_just_pressed("jump"):
		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("move_left", "move_right", "move_forward", "move_backward")
	print("Input Direction:", input_dir)

	var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()

	if direction:
		# Sprinting
		if Input.is_action_pressed("sprinting"):
			velocity.x = direction.x * SPRINT_SPEED
			velocity.z = direction.z * SPRINT_SPEED
		# Regular movement
		else:
			velocity.x = direction.x * SPEED
			velocity.z = direction.z * SPEED
	else:
		velocity.x = 0
		velocity.z = 0

	print("Velocity:", velocity)  # Print the velocity before moving

	# Crouch
	if Input.is_action_pressed("crouching"):
		crouch()
	else:
		stand()

	move_and_slide()  # Apply velocity without arguments

func crouch():
	if not is_crouching:
		is_crouching = true
		scale = crouched_scale
		position.y -= 1.0  # Adjust the position to maintain the same eye level

func stand():
	if is_crouching:
		is_crouching = false
		scale = original_scale
		position.y += 1.0  # Adjust the position when standing up

and still doesnt work

  • xyz replied to this.

    Elroy and still doesnt work

    Of course it doesn't but now you have a clue about why it isn't working. If input_dir is (0,0) this means that Input.get_vector() doesn't return a proper direction vector when you press your commands. Check if action names you use as arguments when calling Input.get_vector() are actually defined in project settings.

    okay but how do i check that ?

    • xyz replied to this.

      Elroy Where did you get those action names from in the first place?

      You can check/map input actions in Project > Project Settings > Input Map

      For a quick start you can try using default actions for cursor keys:

      var input_dir = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")

      i got them from a video on youtube that changes the movement from the arrow keys to the azerty keys

      oke i tried the arrow keys and that does work


      these are the inputs i use

      • xyz replied to this.

        Elroy Looks like you don't have any actual keys mapped to those actions. Click the plus icon for each and assign a key.

        ooooh okay thank you

        thank you its working now, i feel stupid xp but thanks, only thing is when i go crouch and let it go , its like i get puched in the air a little and then back to the ground

        • xyz replied to this.

          Elroy its like i get puched in the air a little and then back to the ground

          That sounds about right according to code you posted.

          how can i change that ?

          • xyz replied to this.

            Elroy how can i change that ?

            This questions is widely unspecific. So all I can answer to that is: by changing the code 🙂

            iv got a other problem now with some code

            func _unhandled_input(event):
            	_mouse_input = event is InputEventMouseMotion and Input.get_mouse_mode()
            Input.MOUSE_MODE_CAPTURED
            	if _mouse_input:
            		_rotation_input = event.relative.x
            		_tilt_input = event.relative.y

            This is the error i get :

            Line 25:Unexpected "Identifier" in class body.
            Line 26:Unexpected "Indent" in class body.
            Line 27:Unexpected "Indent" in class body.
            Line 28:Unexpected "Identifier" in class body.
            Line 30:Expected end of file.

              Elroy Input.MOUSE_MODE_CAPTURED

              Why is that line there? It's not indented, which is causing the error messages.

              It also has no purpose.

              i was watching a video to make mouse movement , idk how to fix it xp

              These two lines:

              _mouse_input = event is InputEventMouseMotion and Input.get_mouse_mode()
              Input.MOUSE_MODE_CAPTURED

              should be this single line:

              _mouse_input = event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED

              thank you but now i can just look down till the camera is fully rotated how do i fix that the camera has a up and down limmit ?

              • xyz replied to this.