Improved component system
This commit is contained in:
@ -1,64 +0,0 @@
|
||||
class_name AnimationController
|
||||
extends Node
|
||||
|
||||
@export var character: Character
|
||||
@export var animation_player: AnimationPlayer
|
||||
|
||||
var next_animation: StringName = "RESET"
|
||||
|
||||
func _ready():
|
||||
assert(character)
|
||||
assert(animation_player)
|
||||
|
||||
func _process(_delta):
|
||||
if character.velocity.y > 0:
|
||||
play("human/jump")
|
||||
elif character.velocity.y < 0:
|
||||
play("human/fall")
|
||||
elif character.direction != Vector3.ZERO:
|
||||
play("human/run-fast")
|
||||
else:
|
||||
play("human/idle")
|
||||
|
||||
if animation_player.current_animation == next_animation:
|
||||
return
|
||||
|
||||
animation_player.play(next_animation)
|
||||
|
||||
func play(action_name: StringName):
|
||||
next_animation = action_name
|
||||
|
||||
# func air(y_velocity: float):
|
||||
# if y_velocity > 0:
|
||||
# play("rifle_jump")
|
||||
# else:
|
||||
# play("falling")
|
||||
|
||||
# func aim(move: Vector2, is_shooting: bool):
|
||||
# if move.x > 0:
|
||||
# play("rifle_aim_strafe_right")
|
||||
# elif move.x < 0:
|
||||
# play("rifle_aim_strafe_left")
|
||||
# elif move.y < 0:
|
||||
# play("rifle_aim_walk_forward")
|
||||
# elif move.y > 0:
|
||||
# play("rifle_aim_walk_backward")
|
||||
# else:
|
||||
# play("rifle_aim")
|
||||
|
||||
# if is_shooting:
|
||||
# play("rifle_shoot")
|
||||
|
||||
# func run(move: Vector2, is_shooting: bool):
|
||||
# if move.y < 0:
|
||||
# play("rifle_run_forward")
|
||||
# elif move.y > 0:
|
||||
# play("rifle_run_backward")
|
||||
# elif move.x > 0:
|
||||
# play("rifle_run_right")
|
||||
# elif move.x < 0:
|
||||
# play("rifle_run_left")
|
||||
# elif is_shooting:
|
||||
# play("rifle_shoot")
|
||||
# else:
|
||||
# play("rifle_idle")
|
@ -1,8 +1,29 @@
|
||||
class_name Player
|
||||
extends Character
|
||||
extends CharacterBody3D
|
||||
|
||||
signal attacked
|
||||
signal dashed
|
||||
signal jumped
|
||||
signal direction_changed
|
||||
|
||||
var controller: Controller
|
||||
|
||||
func attack():
|
||||
attacked.emit()
|
||||
|
||||
func dash():
|
||||
dashed.emit()
|
||||
|
||||
func jump():
|
||||
jumped.emit()
|
||||
|
||||
func set_direction(direction: Vector3):
|
||||
direction_changed.emit(direction)
|
||||
|
||||
# TODO: Remove this:
|
||||
|
||||
var id: String
|
||||
|
||||
func set_character_name(new_name: String):
|
||||
name = new_name
|
||||
get_node("Label").text = name
|
||||
$Label.text = name
|
||||
|
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=11 format=3 uid="uid://2lcnu3dy54lx"]
|
||||
[gd_scene load_steps=13 format=3 uid="uid://2lcnu3dy54lx"]
|
||||
|
||||
[ext_resource type="Script" path="res://player/Player.gd" id="1_8gebs"]
|
||||
[ext_resource type="PackedScene" uid="uid://c8j7t4yg7anb0" path="res://assets/female/Female.blend" id="2_8nah6"]
|
||||
@ -6,17 +6,18 @@
|
||||
[ext_resource type="PackedScene" uid="uid://cgqbkj8wbcatv" path="res://assets/hair/PonyTail.blend" id="3_umw6q"]
|
||||
[ext_resource type="FontFile" uid="uid://b7mov13kwi8u8" path="res://assets/font/ubuntu_nf_regular.ttf" id="4_76ehj"]
|
||||
[ext_resource type="Skin" uid="uid://bbqyiue1vj37f" path="res://assets/hoodie/Hoodie_Skin.tres" id="4_b1tg1"]
|
||||
[ext_resource type="Script" path="res://player/AnimationController.gd" id="4_i2ybk"]
|
||||
[ext_resource type="ArrayMesh" uid="uid://b3qvgfg41b7jo" path="res://assets/hoodie/Hoodie_Mesh.res" id="5_mkrgn"]
|
||||
[ext_resource type="AnimationLibrary" uid="uid://d4n0puibh4hyt" path="res://assets/animations/human.blend" id="6_fl6or"]
|
||||
[ext_resource type="PackedScene" uid="uid://x102pryt2s5a" path="res://character/movement/MovementComponent.tscn" id="8_25qd0"]
|
||||
[ext_resource type="PackedScene" uid="uid://d0onbq0ad1ap4" path="res://character/rotation/RotationComponent.tscn" id="9_agxqu"]
|
||||
[ext_resource type="PackedScene" uid="uid://bivxnxwi863o0" path="res://character/animation/AnimationComponent.tscn" id="10_bcaeg"]
|
||||
[ext_resource type="AnimationLibrary" uid="uid://d4n0puibh4hyt" path="res://assets/animations/human.blend" id="11_d0e6r"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_2f50n"]
|
||||
radius = 0.25
|
||||
height = 1.6
|
||||
|
||||
[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("model") groups=["player"]]
|
||||
[node name="Player" type="CharacterBody3D" groups=["player"]]
|
||||
script = ExtResource("1_8gebs")
|
||||
model = NodePath("Model")
|
||||
|
||||
[node name="Model" type="Node3D" parent="."]
|
||||
|
||||
@ -94,20 +95,6 @@ bone_idx = 12
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.8, 0)
|
||||
shape = SubResource("CapsuleShape3D_2f50n")
|
||||
|
||||
[node name="Animation" type="Node" parent="." node_paths=PackedStringArray("character", "animation_player")]
|
||||
script = ExtResource("4_i2ybk")
|
||||
character = NodePath("..")
|
||||
animation_player = NodePath("../AnimationPlayer")
|
||||
|
||||
[node name="Health" parent="." instance=ExtResource("2_np5ag")]
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
root_node = NodePath("../Model/Female")
|
||||
libraries = {
|
||||
"human": ExtResource("6_fl6or")
|
||||
}
|
||||
playback_default_blend_time = 0.2
|
||||
|
||||
[node name="Label" type="Label3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0)
|
||||
pixel_size = 0.001
|
||||
@ -119,4 +106,20 @@ font = ExtResource("4_76ehj")
|
||||
font_size = 128
|
||||
outline_size = 32
|
||||
|
||||
[node name="Health" parent="." instance=ExtResource("2_np5ag")]
|
||||
|
||||
[node name="Movement" parent="." instance=ExtResource("8_25qd0")]
|
||||
|
||||
[node name="Rotation" parent="." node_paths=PackedStringArray("root") instance=ExtResource("9_agxqu")]
|
||||
root = NodePath("../Model")
|
||||
|
||||
[node name="Animation" parent="." instance=ExtResource("10_bcaeg")]
|
||||
|
||||
[node name="AnimationPlayer" parent="Animation" index="0"]
|
||||
root_node = NodePath("../../Model/Female")
|
||||
libraries = {
|
||||
"human": ExtResource("11_d0e6r")
|
||||
}
|
||||
|
||||
[editable path="Model/Female"]
|
||||
[editable path="Animation"]
|
||||
|
@ -1,5 +0,0 @@
|
||||
class_name Controller
|
||||
extends Node
|
||||
|
||||
## The character that we're controlling.
|
||||
@export var character: Character
|
@ -1,22 +0,0 @@
|
||||
class_name PlayerController
|
||||
extends Controller
|
||||
|
||||
var move: Vector2
|
||||
|
||||
func _unhandled_input(event):
|
||||
if Global.interacting_with_ui:
|
||||
return
|
||||
|
||||
move = Input.get_vector("move_left", "move_right", "move_forward", "move_backward")
|
||||
character.direction = (Global.camera.transform.basis * Vector3(move.x, 0, move.y))
|
||||
character.direction.y = 0
|
||||
character.direction = character.direction.normalized()
|
||||
|
||||
if event.is_action_pressed("jump"):
|
||||
character.jump()
|
||||
|
||||
if event.is_action_pressed("dash"):
|
||||
character.dash()
|
||||
|
||||
if event.is_action_pressed("attack"):
|
||||
character.attack()
|
@ -1,19 +0,0 @@
|
||||
class_name ProxyController
|
||||
extends Controller
|
||||
|
||||
## The authoritative position on the server.
|
||||
var server_position: Vector3
|
||||
|
||||
func _ready():
|
||||
server_position = character.position
|
||||
|
||||
func _process(_delta):
|
||||
var move := server_position - character.position
|
||||
move.y = 0.0
|
||||
|
||||
if move.length_squared() < 0.01:
|
||||
character.direction = Vector3.ZERO
|
||||
return
|
||||
|
||||
character.direction = Vector3(move.x, 0, move.z)
|
||||
character.direction = character.direction.normalized()
|
Reference in New Issue
Block a user