-
Notifications
You must be signed in to change notification settings - Fork 1
/
character_body_3d.gd
54 lines (42 loc) · 1.53 KB
/
character_body_3d.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
extends CharacterBody3D
const SPEED = 3.0
const JUMP_VELOCITY = 4.5
const SENS_X = 0.001
const SENS_Y = 0.001
@onready var camera_3d: Camera3D = $Camera3D
@onready var animation_player: AnimationPlayer = $"../v22 level_01_Imported/AnimationPlayer"
func _ready() -> void:
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
func _input(event: InputEvent) -> void:
if event is InputEventMouseMotion:
var event_mm: InputEventMouseMotion = event
camera_3d.rotate_x(-event_mm.relative.y * SENS_Y)
rotate_y(-event_mm.relative.x * SENS_X)
pass
var door_open := false
func _physics_process(delta: float) -> void:
if Input.is_action_just_pressed("anim"):
if not animation_player.is_playing():
if not door_open:
animation_player.play("cage_open")
door_open = true
else:
animation_player.play_backwards("cage_open")
door_open = false
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# 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", "back")
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()