asset vibe
This commit is contained in:
@@ -2,6 +2,10 @@ extends CharacterBody3D
|
||||
|
||||
@export var stats: PlayerStats
|
||||
|
||||
var anim_player: AnimationPlayer = null
|
||||
var current_anim: String = ""
|
||||
var attack_lock_until: float = 0.0
|
||||
|
||||
func _ready() -> void:
|
||||
add_to_group("player")
|
||||
PlayerData.init_from_resource(stats)
|
||||
@@ -10,3 +14,46 @@ func _ready() -> void:
|
||||
PlayerData.returning_from_dungeon = false
|
||||
elif PlayerData.dungeon_cleared:
|
||||
PlayerData.clear_cache()
|
||||
anim_player = get_node_or_null("Mesh/Model/AnimationPlayer")
|
||||
_play_anim("Idle")
|
||||
EventBus.attack_executed.connect(_on_attack_executed)
|
||||
EventBus.entity_died.connect(_on_entity_died)
|
||||
EventBus.player_respawned.connect(_on_player_respawned)
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if not PlayerData.alive:
|
||||
return
|
||||
var now: float = Time.get_ticks_msec() / 1000.0
|
||||
if now < attack_lock_until:
|
||||
return
|
||||
if velocity.length() > 0.1:
|
||||
_play_anim("Running_A")
|
||||
else:
|
||||
_play_anim("Idle")
|
||||
|
||||
func _play_anim(anim_name: String, loop: bool = true) -> void:
|
||||
if not anim_player:
|
||||
return
|
||||
if current_anim == anim_name:
|
||||
return
|
||||
if not anim_player.has_animation(anim_name):
|
||||
return
|
||||
var anim: Animation = anim_player.get_animation(anim_name)
|
||||
if anim:
|
||||
anim.loop_mode = Animation.LOOP_LINEAR if loop else Animation.LOOP_NONE
|
||||
anim_player.play(anim_name)
|
||||
current_anim = anim_name
|
||||
|
||||
func _on_attack_executed(attacker: Node, _pos: Vector3, _dir: Vector3, _damage: float) -> void:
|
||||
if attacker != self:
|
||||
return
|
||||
_play_anim("1H_Melee_Attack_Chop", false)
|
||||
attack_lock_until = Time.get_ticks_msec() / 1000.0 + 0.5
|
||||
|
||||
func _on_entity_died(entity: Node) -> void:
|
||||
if entity != PlayerData:
|
||||
return
|
||||
_play_anim("Death_A", false)
|
||||
|
||||
func _on_player_respawned(_player: Node) -> void:
|
||||
_play_anim("Idle")
|
||||
|
||||
@@ -25,6 +25,11 @@ func _physics_process(delta: float) -> void:
|
||||
if direction:
|
||||
player.velocity.x = direction.x * PlayerData.speed
|
||||
player.velocity.z = direction.z * PlayerData.speed
|
||||
var world_yaw: float = atan2(-direction.x, -direction.z)
|
||||
var local_yaw: float = world_yaw - player.rotation.y
|
||||
var mesh: Node3D = player.get_node_or_null("Mesh") as Node3D
|
||||
if mesh:
|
||||
mesh.rotation.y = lerp_angle(mesh.rotation.y, local_yaw, 10.0 * delta)
|
||||
else:
|
||||
player.velocity.x = move_toward(player.velocity.x, 0, PlayerData.speed)
|
||||
player.velocity.z = move_toward(player.velocity.z, 0, PlayerData.speed)
|
||||
|
||||
@@ -7,15 +7,12 @@
|
||||
[ext_resource type="Script" uid="uid://b05nkuryipwny" path="res://scenes/player/targeting.gd" id="8"]
|
||||
[ext_resource type="Script" uid="uid://dhomrampxola4" path="res://scenes/player/role/role.gd" id="10"]
|
||||
[ext_resource type="Resource" uid="uid://btd0g0oiulssq" path="res://scenes/player/player_stats.tres" id="14"]
|
||||
[ext_resource type="PackedScene" path="res://assets/models/characters/Knight.glb" id="15"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_1"]
|
||||
radius = 0.3
|
||||
height = 1.8
|
||||
|
||||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_1"]
|
||||
radius = 0.3
|
||||
height = 1.8
|
||||
|
||||
[node name="Player" type="CharacterBody3D" unique_id=197716516]
|
||||
script = ExtResource("1")
|
||||
stats = ExtResource("14")
|
||||
@@ -23,8 +20,10 @@ stats = ExtResource("14")
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="." unique_id=311205642]
|
||||
shape = SubResource("CapsuleShape3D_1")
|
||||
|
||||
[node name="Mesh" type="MeshInstance3D" parent="." unique_id=1514179122]
|
||||
mesh = SubResource("CapsuleMesh_1")
|
||||
[node name="Mesh" type="Node3D" parent="." unique_id=1514179122]
|
||||
|
||||
[node name="Model" parent="Mesh" instance=ExtResource("15")]
|
||||
transform = Transform3D(-1, 0, 0, 0, 1, 0, 0, 0, -1, 0, -0.9, 0)
|
||||
|
||||
[node name="CameraPivot" type="Node3D" parent="." unique_id=1881685457]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0)
|
||||
|
||||
Reference in New Issue
Block a user