47 lines
1.3 KiB
GDScript3
47 lines
1.3 KiB
GDScript3
|
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()
|