my code doesnt seem to work pls help me
how can i change that ?
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.
- Edited
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
- Edited
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 ?
func _ready():
original_scale = scale
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _input(event):
if event is InputEventMouseMotion:
rotate_y(deg_to_rad(-event.relative.x * mouse_sens))
head.rotate_x(deg_to_rad(-event.relative.y * mouse_sens))
this is what i have
iv got a other problem i imprted a rooted model from mixamo and now my cammera movement is broken if i move my cursor the cammera does a barrel rol , and also my keybinds are broken
extends CharacterBody3D
@onready var head = $Head
const walking_speed = 5.0
const sprint_speed = 10.0
const crouch_speed = 1.0
const JUMP_VELOCITY = 3.4 # Increase the jump velocity for a more noticeable effect
const mouse_sens = 0.1
var direction = Vector3()
# 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.8, 1) # Adjust the vertical scale for a less deep crouch
func _ready():
original_scale = scale
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _input(event):
if event is InputEventMouseMotion:
rotate_y(deg_to_rad(-event.relative.x * mouse_sens))
head.rotate_x(deg_to_rad(-event.relative.y * mouse_sens))
head.rotation.x = clamp(head.rotation.x, deg_to_rad(-50.0), deg_to_rad(30.0))
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y -= gravity * delta
Global.debug.add_property("MovementSpeed",walking_speed, 1)
Global.debug.add_property("Crouching",is_crouching, 2)
# 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.
var direction = Vector3()
if Input.is_action_pressed("move_forward"):
direction -= transform.basis.z
elif Input.is_action_pressed("move_backward"):
direction += transform.basis.z
if Input.is_action_pressed("move_left"):
direction -= transform.basis.x
elif Input.is_action_pressed("move_right"):
direction += transform.basis.x
direction.y = 0 # Ensure no vertical movement
direction = direction.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 * walking_speed
velocity.z = direction.z * walking_speed
else:
velocity.x = 0
velocity.z = 0
# Crouch
if Input.is_action_pressed("crouching"):
crouch()
else:
stand()
move_and_slide() # Apply velocity with arguments
func crouch():
if not is_crouching:
is_crouching = true
scale = crouched_scale
position.y -= 0.5 # Adjust the crouch height to a less deep position
move_and_slide() # Stop the character's movement when crouching
func stand():
if is_crouching:
is_crouching = false
scale = original_scale
position.y += 0.2 # Adjust the standing position when returning from crouch
move_and_slide() # Stop the character's movement when standing up