大客流--人的动画控制备用

This commit is contained in:
joylink_zhaoerwei 2024-06-17 13:15:00 +08:00
parent f67fcc5fe1
commit 3246c46577
16 changed files with 1617 additions and 0 deletions

BIN
Model/people/people.glb Normal file

Binary file not shown.

View File

@ -0,0 +1,34 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://dif5iaw78818l"
path="res://.godot/imported/people.glb-62bc0b5c85ed5a480c8eeb4d8043d67f.scn"
[deps]
source_file="res://Model/people/people.glb"
dest_files=["res://.godot/imported/people.glb-62bc0b5c85ed5a480c8eeb4d8043d67f.scn"]
[params]
nodes/root_type=""
nodes/root_name=""
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
import_script/path=""
_subresources={}
gltf/naming_version=1
gltf/embedded_image_handling=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

View File

@ -0,0 +1,36 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cxcfm31rnpsh4"
path.s3tc="res://.godot/imported/people_DKL_SB_J.jpg-f39f041a529fd3cfc3493af8ca188db9.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
generator_parameters={}
[deps]
source_file="res://Model/people/people_DKL_SB_J.jpg"
dest_files=["res://.godot/imported/people_DKL_SB_J.jpg-f39f041a529fd3cfc3493af8ca188db9.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

View File

@ -0,0 +1,36 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cmwordcwuj802"
path.s3tc="res://.godot/imported/people_n_bigys_1.jpg-bedd72229e926543012b08dd6ea5fffd.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
generator_parameters={}
[deps]
source_file="res://Model/people/people_n_bigys_1.jpg"
dest_files=["res://.godot/imported/people_n_bigys_1.jpg-bedd72229e926543012b08dd6ea5fffd.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

9
sceen/people/Idle.gd Normal file
View File

@ -0,0 +1,9 @@
extends StateBase
## 玩家节点
@export var player:Player
func enter() -> void:
##运行父类方法
super.enter()
player.people.is_moving = false

52
sceen/people/Player.gd Normal file
View File

@ -0,0 +1,52 @@
extends CharacterBody3D
##玩家
class_name Player
@onready var people: Node3D = $people
@onready var state_machine: StateMachine = $StateMachine
##导航
@onready var navigation_agent_3d: NavigationAgent3D = $NavigationAgent3D
var speed:float = 4
var stop_distance:float = 1
signal ArriveTargetPos
##设置目标位(寻路方式运动)
func setTargetPos(targetPos:Vector3,stopDistance = 1)-> void:
stop_distance = stopDistance
navigation_agent_3d.target_position = targetPos
navigation_agent_3d.target_position =navigation_agent_3d.get_final_position()
##去目标位
func goToTarget()-> void:
$NavigationTimer.start()
##停止移动
func stopToTarget()-> void:
$NavigationTimer.stop()
state_machine.change_state("Idle")
func _on_navigation_timer_timeout() -> void:
var direction_3d = (navigation_agent_3d.get_next_path_position() - global_position).normalized()
velocity = direction_3d*speed
look_at_from_position(global_position, navigation_agent_3d.get_next_path_position())
if navigation_agent_3d.distance_to_target() > stop_distance :
move_and_slide()
state_machine.change_state("Walk")
else :
stopToTarget()
ArriveTargetPos.emit()
##区域碰撞检测相关
signal AreaEnter(area: Area3D)
signal AreaExit(area: Area3D)
func _on_area_3d_area_entered(area: Area3D) -> void:
AreaEnter.emit(area)
func _on_area_3d_area_exited(area: Area3D) -> void:
AreaExit.emit(area)

View File

@ -0,0 +1,21 @@
extends Node3D
## 基础状态
class_name StateBase
var state_machine: StateMachine
## 进入状态
func enter() -> void:
pass
## 退出状态
func exit() -> void:
pass
## 渲染帧触发
@warning_ignore("unused_parameter")
func process_update(delta: float) -> void:
pass
## 物理帧触发
@warning_ignore("unused_parameter")
func physics_process_update(delta: float) -> void:
pass

View File

@ -0,0 +1,30 @@
extends Node3D
## 角色状态机
class_name StateMachine
## 默认状态
@export var current_state: StateBase
func _ready() -> void:
##StateMachine中的所有子节点
for child in get_children():
if child is StateBase:
child.state_machine = self
await get_parent().ready
current_state.enter()
func _process(delta: float) -> void:
current_state.process_update(delta)
## 修改状态 对每一种状态拆分编写
func change_state(target_state_name: String) -> void:
var target_state = get_node_or_null(target_state_name)
if target_state == null:
printerr("状态传入错误")
return
##退出当前状态
current_state.exit()
##切换为目标状态
current_state = target_state
current_state.enter()

9
sceen/people/Walk.gd Normal file
View File

@ -0,0 +1,9 @@
extends StateBase
## 玩家节点
@export var player:Player
func enter() -> void:
##运行父类方法
super.enter()
player.people.is_moving = true

17
sceen/people/people.gd Normal file
View File

@ -0,0 +1,17 @@
extends Node3D
@onready var animation_player: AnimationPlayer = $AnimationPlayer
@onready var animation_tree: AnimationTree = $AnimationTree
##动画状态机
@onready var state_machine: AnimationNodeStateMachinePlayback = animation_tree.get("parameters/StateMachine/playback")
##玩家是否移动
@onready var is_moving : bool = false :
set(value):
is_moving = value
if is_moving:
#animation_player.play("walking")
state_machine.travel("walking")
else :
#animation_player.play("idle")
state_machine.travel("idle")

1252
sceen/people/people.tscn Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,46 @@
extends Node3D
##玩家
class_name PlayerPathFollow
@onready var player: Player = $Player
@onready var path_3d: Path3D = $Path3D
##设置路线点坐标
func setPathPoints(points : Array,angle :Vector3 = Vector3()) -> void:
var curve = Curve3D.new()
for index in range(points.size()):
if angle != null and index ==0 :
curve.add_point(points[index],Vector3(),angle)
if index > 0 :
curve.add_point(points[index])
path_3d.curve = curve
$Path3D/PathFollow3D.progress = 0
##沿路线走
func peopleBeginWalk() -> void:
$Path3D/PathFollowTimer.start()
$Player.state_machine.change_state("Walk")
##沿路线停
func peopleStopWalk()-> void:
$Path3D/PathFollowTimer.stop()
$Player.state_machine.change_state("Idle")
func _on_path_follow_timer_timeout() -> void:
var lastProgress = $Path3D/PathFollow3D.progress
$Path3D/PathFollow3D.progress += 0.068
if lastProgress == $Path3D/PathFollow3D.progress and !$Path3D/PathFollow3D.loop :
peopleStopWalk()
player.ArriveTargetPos.emit()
func _on_player_area_enter(area: Area3D) -> void:
if area.is_in_group('needStopWalk') or area.is_in_group('player'):
peopleStopWalk()
func _on_player_area_exit(area: Area3D) -> void:
if area.is_in_group('needStopWalk') or area.is_in_group('player') :
peopleBeginWalk()

View File

@ -0,0 +1,24 @@
[gd_scene load_steps=3 format=3 uid="uid://ce8bos77837mf"]
[ext_resource type="Script" path="res://sceen/people/peopleWalkFollow.gd" id="1_bcdcn"]
[ext_resource type="PackedScene" uid="uid://c6noskjp3ks4p" path="res://sceen/people/player.tscn" id="2_tl7k2"]
[node name="peopleWalkFollow" type="Node3D"]
script = ExtResource("1_bcdcn")
[node name="Player" parent="." instance=ExtResource("2_tl7k2")]
[node name="Path3D" type="Path3D" parent="."]
[node name="PathFollow3D" type="PathFollow3D" parent="Path3D"]
loop = false
[node name="RemoteTransform3D" type="RemoteTransform3D" parent="Path3D/PathFollow3D"]
remote_path = NodePath("../../../Player")
[node name="PathFollowTimer" type="Timer" parent="Path3D"]
wait_time = 0.05
[connection signal="AreaEnter" from="Player" to="." method="_on_player_area_enter"]
[connection signal="AreaExit" from="Player" to="." method="_on_player_area_exit"]
[connection signal="timeout" from="Path3D/PathFollowTimer" to="." method="_on_path_follow_timer_timeout"]

51
sceen/people/player.tscn Normal file
View File

@ -0,0 +1,51 @@
[gd_scene load_steps=7 format=3 uid="uid://c6noskjp3ks4p"]
[ext_resource type="Script" path="res://sceen/people/Player.gd" id="1_pursd"]
[ext_resource type="PackedScene" uid="uid://ql5aokids4f6" path="res://sceen/people/people.tscn" id="2_ggqm4"]
[ext_resource type="Script" path="res://sceen/people/StateMachine/StateMachine.gd" id="3_ltxep"]
[ext_resource type="Script" path="res://sceen/people/Idle.gd" id="4_ru6er"]
[ext_resource type="Script" path="res://sceen/people/Walk.gd" id="5_aav7k"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_n25t3"]
radius = 0.3
[node name="Player" type="CharacterBody3D"]
script = ExtResource("1_pursd")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.701889, 0)
visible = false
shape = SubResource("CapsuleShape3D_n25t3")
[node name="people" parent="." instance=ExtResource("2_ggqm4")]
transform = Transform3D(-1, 0, -1.50996e-07, 0, 1, 0, 1.50996e-07, 0, -1, 0, 0, 0)
[node name="Area3D" type="Area3D" parent="." groups=["player"]]
[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.701889, 0)
shape = SubResource("CapsuleShape3D_n25t3")
[node name="StateMachine" type="Node3D" parent="." node_paths=PackedStringArray("current_state")]
script = ExtResource("3_ltxep")
current_state = NodePath("Idle")
[node name="Idle" type="Node3D" parent="StateMachine" node_paths=PackedStringArray("player")]
script = ExtResource("4_ru6er")
player = NodePath("../..")
[node name="Walk" type="Node3D" parent="StateMachine" node_paths=PackedStringArray("player")]
script = ExtResource("5_aav7k")
player = NodePath("../..")
[node name="NavigationAgent3D" type="NavigationAgent3D" parent="."]
avoidance_enabled = true
height = 2.0
debug_enabled = true
[node name="NavigationTimer" type="Timer" parent="."]
wait_time = 0.05
[connection signal="area_entered" from="Area3D" to="." method="_on_area_3d_area_entered"]
[connection signal="area_exited" from="Area3D" to="." method="_on_area_3d_area_exited"]
[connection signal="timeout" from="NavigationTimer" to="." method="_on_navigation_timer_timeout"]