Advertisement
AIwinter

godot boom

Mar 31st, 2025
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. extends CharacterBody3D
  2.  
  3. @export var camera_sensitivity: float = 0.005
  4.  
  5. const SPEED = 5.0
  6. const JUMP_VELOCITY = 4.5
  7.  
  8. @onready var spring_arm = $SpringArm3D # Получаем ссылку на SpringArm3D
  9.  
  10. var rotation_x = 0.0 # Угол наклона камеры
  11.  
  12. func _ready():
  13. Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
  14.  
  15. func _input(event):
  16. if event is InputEventMouseMotion:
  17. # Вращение вокруг персонажа (по оси Y)
  18. rotate_y(-event.relative.x * camera_sensitivity)
  19.  
  20. # Ограничиваем наклон камеры (по оси X)
  21. rotation_x = clamp(rotation_x - event.relative.y * camera_sensitivity, -0.5, 0.5)
  22. spring_arm.rotation.x = rotation_x
  23.  
  24. func _physics_process(delta: float) -> void:
  25. # Add the gravity.
  26. if not is_on_floor():
  27. velocity += get_gravity() * delta
  28.  
  29. # Handle jump.
  30. if Input.is_action_just_pressed("ui_accept") and is_on_floor():
  31. velocity.y = JUMP_VELOCITY
  32.  
  33. # Get the input direction and handle the movement/deceleration.
  34. # As good practice, you should replace UI actions with custom gameplay actions.
  35. var input_dir := Input.get_vector("ui_left", "ui_right", "ui_down", "ui_up")
  36. var direction := (transform.basis * Vector3(input_dir.y, 0, input_dir.x)).normalized()
  37. if direction:
  38. velocity.x = direction.x * SPEED
  39. velocity.z = direction.z * SPEED
  40. else:
  41. velocity.x = move_toward(velocity.x, 0, SPEED)
  42. velocity.z = move_toward(velocity.z, 0, SPEED)
  43.  
  44. move_and_slide()
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement