-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3d_godot_robot.gd
More file actions
45 lines (30 loc) · 999 Bytes
/
3d_godot_robot.gd
File metadata and controls
45 lines (30 loc) · 999 Bytes
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
class_name Body
extends Node3D
const LERP_VELOCITY = 0.15
@export_category("Objects")
@export var _character: Character = null
@export var animation_player: AnimationPlayer = null
func apply_rotation(_velocity: Vector3) -> void:
var new_rotation_y := lerp_angle(rotation.y, atan2(-_velocity.x, -_velocity.z), LERP_VELOCITY)
rotation.y = new_rotation_y
sync_player_rotation.rpc(new_rotation_y)
func apply_rotation_first_person(angle: float) -> void:
rotation.y = angle
sync_player_rotation.rpc(angle)
func animate(_velocity: Vector3) -> void:
if not _character.is_on_floor():
if _velocity.y < 0:
animation_player.play("Fall")
else:
animation_player.play("Jump")
return
if _velocity:
if _character.is_running() and _character.is_on_floor():
animation_player.play("Sprint")
return
animation_player.play("Run")
return
animation_player.play("Idle")
@rpc("any_peer", "reliable")
func sync_player_rotation(rotation_y: float) -> void:
rotation.y = rotation_y