2024-06-17 13:15:00 +08:00
|
|
|
|
extends Node3D
|
|
|
|
|
|
|
|
|
|
##玩家
|
|
|
|
|
class_name PlayerPathFollow
|
|
|
|
|
|
|
|
|
|
@onready var player: Player = $Player
|
|
|
|
|
|
|
|
|
|
@onready var path_3d: Path3D = $Path3D
|
|
|
|
|
|
2024-06-18 15:47:23 +08:00
|
|
|
|
##生成时候的全局位置坐标,用于之后player偏移量计算
|
|
|
|
|
var buildPos = Vector3()
|
|
|
|
|
|
2024-07-11 17:49:28 +08:00
|
|
|
|
##默认是在A区域生成
|
|
|
|
|
var generateArea = 'A'
|
|
|
|
|
|
2024-07-09 17:27:43 +08:00
|
|
|
|
var speed:float = 1
|
2024-07-05 18:22:52 +08:00
|
|
|
|
|
|
|
|
|
#生成时候的id
|
|
|
|
|
var id = 0
|
|
|
|
|
|
2024-06-17 13:15:00 +08:00
|
|
|
|
##设置路线点坐标
|
|
|
|
|
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:
|
2024-06-18 15:47:23 +08:00
|
|
|
|
player.currentExerciseType = player.Exercise_type.pathFollow
|
2024-06-20 10:28:46 +08:00
|
|
|
|
if not $Path3D/PathFollowTimer.is_inside_tree() :
|
|
|
|
|
return
|
2024-06-17 13:15:00 +08:00
|
|
|
|
$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
|
2024-07-05 18:22:52 +08:00
|
|
|
|
$Path3D/PathFollow3D.progress += 0.068 * speed
|
2024-06-17 13:15:00 +08:00
|
|
|
|
if lastProgress == $Path3D/PathFollow3D.progress and !$Path3D/PathFollow3D.loop :
|
|
|
|
|
peopleStopWalk()
|
|
|
|
|
player.ArriveTargetPos.emit()
|
2024-06-18 15:47:23 +08:00
|
|
|
|
player.currentExerciseType = player.Exercise_type.no
|
2024-06-17 13:15:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_player_area_enter(area: Area3D) -> void:
|
2024-06-18 15:47:23 +08:00
|
|
|
|
if player.currentExerciseType == player.Exercise_type.pathFollow and (area.is_in_group('needStopWalk') or area.is_in_group('player')):
|
2024-06-17 13:15:00 +08:00
|
|
|
|
peopleStopWalk()
|
|
|
|
|
|
2024-07-15 10:29:36 +08:00
|
|
|
|
var waitTimeWalkAgain = 0.2
|
2024-06-17 13:15:00 +08:00
|
|
|
|
func _on_player_area_exit(area: Area3D) -> void:
|
2024-06-18 15:47:23 +08:00
|
|
|
|
if player.currentExerciseType == player.Exercise_type.pathFollow and (area.is_in_group('needStopWalk') or area.is_in_group('player')) :
|
2024-07-15 10:29:36 +08:00
|
|
|
|
await get_tree().create_timer(waitTimeWalkAgain).timeout
|
2024-06-17 13:15:00 +08:00
|
|
|
|
peopleBeginWalk()
|