I need help guys

there is a code for simple first-person walking around, and all works perfectly, but when i stand still and trying look around with my mouse - the character continues moving around for some reason, i need he just to stand in place while i’m moving my mouse. Here is the code
`extends CharacterBody3D

@onready var head = $head
var curSPEED = 5.0
const JUMP_VELOCITY = 4.5


const walking = 5
const sprint = 10
const crouch = 3
const sens = 0.01
var incline = 4.0
var lerp_speed = 10.0

Get the gravity from the project settings to be synced with RigidBody nodes.

var gravity = ProjectSettings.get_setting(“physics/3d/default_gravity”)

func _ready():
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
func _input(event):
if event is InputEventMouseMotion:
rotate_y(-event.relative.x * sens)
head.rotate_x(-event.relative.y * sens)
head.rotation.x = clamp(head.rotation.x, deg_to_rad(-89), deg_to_rad(89))

func _physics_process(delta):

if Input.is_action_pressed("crouch"):
	curSPEED = crouch
	head.position.y = lerp(head.position.y, incline, delta*lerp_speed)
	head.position.y = lerp(head.position.y, 6.0, delta*lerp_speed)
	if Input.is_action_pressed("sprint"):
		curSPEED = sprint
		curSPEED = walking
# Add the gravity.
if not is_on_floor():
	velocity.y -= 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("left", "right", "forward", "backward")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
	velocity.x = direction.x *curSPEED
	velocity.z = direction.z *curSPEED
	velocity.x = move_toward(velocity.x, 0, curSPEED)
	velocity.z = move_toward(velocity.z, 0, curSPEED)


please, help

Could you send a video of the issue in action?

sure, i think there need to be some bool operations

i can’t upload, unfortunately

maybe you have some social media? i can send it straight to you

quite possibly. This looks very similar to my character controller, I do notice that with your current code structure, it is constantly trying to lerp your head position up, instead of only trying to lerp it whenever you stop crouching; however, I don’t think that it would lead to your camera inputs moving the character.

Is the file too large? I have no problem uploading mp4 files to the godot forums.

it’s because i was sign up recently

give me one minute

1 Like

Ok, that makes sense. you could email it to me at lasgana.bee.studios@gmail.com, or you could upload it to a google drive and have us view it there

I notice that you are rotating the player instead of the camera or head here.

1 Like

Thank you, this is very helpful.

maybe i need to replace some part of the script to camera

this could be causing the rotation if the camera is not perfectly centered to the CharacterBody3D. What is the hierarchy of your player scene?

there are solutions that would involve moving the camera script out of the player script and onto the camera, but in my experience, it is much easier to put it directly into the character script.



well, it is what i did, no?

Okay, thank you. I would change rotate_y(-event.relative.x * sens) to be $head/Camera3d.rotate_y(-event.relative.x * sens)