Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends CharacterBody3D
- #VARIABLES N SHIT
- var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
- var speed = 5
- var jump_speed = 5
- var mouse_sensitivity = 0.05
- var staminam = 100
- var staminac = staminam
- var sprintready = true
- #ACTUAL MOVEMENT
- func _physics_process(delta):
- velocity.y += -gravity * delta
- var input = Input.get_vector("left", "right", "forward", "back")
- var movement_dir = transform.basis * Vector3(input.x, 0, input.y)
- velocity.x = movement_dir.x * speed
- velocity.z = movement_dir.z * speed
- #RUN
- if Input.is_action_pressed("sprint") and staminac and sprintready:
- staminac -= 1
- speed = 10
- elif !Input.is_action_pressed("sprint") and staminac < staminam:
- staminac += 5
- if staminac > staminam:
- staminac = staminam
- if staminac == staminam:
- sprintready = true
- elif staminac <= 0:
- sprintready = false
- if Input.is_action_just_released("sprint") or staminac <=0:
- speed = 5
- move_and_slide()
- #JUMP
- if is_on_floor() and Input.is_action_just_pressed("jump"):
- velocity.y = jump_speed
- #CAMERA
- func _ready():
- Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
- func _input(event):
- if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
- rotate_y(-event.relative.x * mouse_sensitivity)
- $Camera3D.rotate_x(-event.relative.y * mouse_sensitivity)
- $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