Godot Math
行列
Basis
1 extends CharacterBody3D
2
3 @export var speed = 16
4 @export var fall_acceleration = 75
5
6 var target_velocity = Vector3.ZERO
7
8 func _physics_process(delta: float) -> void:
9 var direction = Vector3.ZERO
10
11 if Input.is_action_pressed("ui_left"):
12 direction.x -= 1
13
14 if Input.is_action_pressed("ui_right"):
15 direction.x += 1
16
17 if Input.is_action_pressed("ui_up"):
18 direction.z -= 1
19
20 if Input.is_action_pressed("ui_down"):
21 direction.z += 1
22
23 if self.is_on_floor() and Input.is_action_just_pressed("jump"):
24 target_velocity.y += 50
25
26 if direction != Vector3.ZERO:
27 direction = direction.normalized()
28 get_node("foo").basis = Basis.looking_at(direction)
29
30 target_velocity.x = direction.x * speed
31 target_velocity.z = direction.z * speed
32
33 if not is_on_floor():
34 target_velocity.y = target_velocity.y - (fall_acceleration * delta)
35
36 velocity = target_velocity
37 self.move_and_slide()