Advertisement
fuks44

Untitled

Feb 24th, 2024
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GDScript 1.10 KB | Gaming | 0 0
  1. extends CharacterBody3D
  2.  
  3. const SPEED = 5
  4. const JUMP_VELOCITY = 5.0
  5. var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
  6. var mouse_sensitivity = 0.5
  7.  
  8. # Câmera
  9. var camera
  10.  
  11. func _ready():
  12.     camera = $Camera3D
  13.     Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
  14.  
  15. func _input(event):
  16.     if event is InputEventMouseMotion:
  17.         rotate_y(deg_to_rad(-event.relative.x * mouse_sensitivity))
  18.         var new_rotation = camera.rotation.x - deg_to_rad(event.relative.y * mouse_sensitivity)
  19.         camera.rotation.x = clamp(new_rotation, deg_to_rad(-70), deg_to_rad(70))
  20.  
  21. func _physics_process(delta):
  22.     if not is_on_floor():
  23.         velocity.y -= gravity * delta
  24.  
  25.     if Input.is_action_just_pressed("ui_accept") and is_on_floor():
  26.         velocity.y = JUMP_VELOCITY
  27.  
  28.     var input_dir = Input.get_vector("A", "D", "W", "S")
  29.     var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
  30.     if direction:
  31.         velocity.x = direction.x * SPEED
  32.         velocity.z = direction.z * SPEED
  33.     else:
  34.         velocity.x = move_toward(velocity.x, 0, SPEED)
  35.         velocity.z = move_toward(velocity.z, 0, SPEED)
  36.  
  37.     move_and_slide()
  38.  
Tags: Script Godot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement