Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends CharacterBody3D
- @export var camera_sensitivity: float = 0.005
- const SPEED = 5.0
- const JUMP_VELOCITY = 4.5
- @onready var spring_arm = $SpringArm3D # Получаем ссылку на SpringArm3D
- var rotation_x = 0.0 # Угол наклона камеры
- func _ready():
- Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
- func _input(event):
- if event is InputEventMouseMotion:
- # Вращение вокруг персонажа (по оси Y)
- rotate_y(-event.relative.x * camera_sensitivity)
- # Ограничиваем наклон камеры (по оси X)
- rotation_x = clamp(rotation_x - event.relative.y * camera_sensitivity, -0.5, 0.5)
- spring_arm.rotation.x = rotation_x
- 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_down", "ui_up")
- var direction := (transform.basis * Vector3(input_dir.y, 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)
- move_and_slide()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement