Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends CharacterBody3D
- const SPEED = 5
- const JUMP_VELOCITY = 5.0
- var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
- var mouse_sensitivity = 0.5
- # Câmera
- var camera
- func _ready():
- camera = $Camera3D
- Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
- func _input(event):
- if event is InputEventMouseMotion:
- rotate_y(deg_to_rad(-event.relative.x * mouse_sensitivity))
- var new_rotation = camera.rotation.x - deg_to_rad(event.relative.y * mouse_sensitivity)
- camera.rotation.x = clamp(new_rotation, deg_to_rad(-70), deg_to_rad(70))
- func _physics_process(delta):
- if not is_on_floor():
- velocity.y -= gravity * delta
- if Input.is_action_just_pressed("ui_accept") and is_on_floor():
- velocity.y = JUMP_VELOCITY
- var input_dir = Input.get_vector("A", "D", "W", "S")
- var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).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