-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplayer.gd
55 lines (42 loc) · 1.67 KB
/
player.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
extends CharacterBody3D
const SPEED = 10.0
const JUMP_VELOCITY = 5
const mouse_sensitivity = 0.002
@onready var main = $"../main"
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
# Initialize the animation player and the audio stream players
@onready var camera = $Camera3D
func _input(event):
if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
rotate_y(-event.relative.x * mouse_sensitivity)
camera.rotate_x(-event.relative.y * mouse_sensitivity)
camera.rotation.x = clampf(camera.rotation.x, -deg_to_rad(70), deg_to_rad(70))
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y -= gravity * delta
# Handle Jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Handle the left mouse button (fire) event
if Input.is_action_just_pressed("fire"):
main.shoot()
if Input.is_action_just_pressed("reload"):
main.reload()
if Input.is_action_just_pressed("ads"):
main.ads_func()
if Input.is_action_just_pressed("inspect"):
main.draw()
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var input_dir = Input.get_vector("left", "right", "forward", "backward")
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()
main.idle()