Advertisement
Guest User

ppeee

a guest
Oct 29th, 2024
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. extends CharacterBody3D
  2. #VARIABLES N SHIT
  3. var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
  4. var speed = 5
  5. var jump_speed = 5
  6. var mouse_sensitivity = 0.05
  7. var staminam = 100
  8. var staminac = staminam
  9. var sprintready = true
  10. #ACTUAL MOVEMENT
  11. func _physics_process(delta):
  12. velocity.y += -gravity * delta
  13. var input = Input.get_vector("left", "right", "forward", "back")
  14. var movement_dir = transform.basis * Vector3(input.x, 0, input.y)
  15. velocity.x = movement_dir.x * speed
  16. velocity.z = movement_dir.z * speed
  17. #RUN
  18. if Input.is_action_pressed("sprint") and staminac and sprintready:
  19. staminac -= 1
  20. speed = 10
  21. elif !Input.is_action_pressed("sprint") and staminac < staminam:
  22. staminac += 5
  23. if staminac > staminam:
  24. staminac = staminam
  25. if staminac == staminam:
  26. sprintready = true
  27. elif staminac <= 0:
  28. sprintready = false
  29. if Input.is_action_just_released("sprint") or staminac <=0:
  30. speed = 5
  31. move_and_slide()
  32. #JUMP
  33. if is_on_floor() and Input.is_action_just_pressed("jump"):
  34. velocity.y = jump_speed
  35. #CAMERA
  36. func _ready():
  37. Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
  38. func _input(event):
  39. if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
  40. rotate_y(-event.relative.x * mouse_sensitivity)
  41. $Camera3D.rotate_x(-event.relative.y * mouse_sensitivity)
  42. $Camera3D.rotation.x = clampf($Camera3D.rotation.x, -deg_to_rad(70), deg_to_rad(70))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement