Reintroduce AutoPathFollow as cleaner base class of MovingPlatform
This commit is contained in:
parent
478a871ee9
commit
4510dd2293
|
@ -1,35 +1,17 @@
|
|||
class_name MovingPlatform extends PathFollow3D
|
||||
class_name MovingPlatform extends AutoPathFollow
|
||||
|
||||
@export var speed: float = 1.0
|
||||
@export var pause_at_ends: float = 1.0
|
||||
@export var body: AnimatableBody3D
|
||||
@export var area: Area3D
|
||||
|
||||
@onready var _prev_position := global_position
|
||||
@onready var _area_bodies: Array[Character] = []
|
||||
|
||||
var direction: float = 1.0
|
||||
var pause_timer: float = 0.0
|
||||
|
||||
func _ready() -> void:
|
||||
if area:
|
||||
area.body_entered.connect(_on_area_body_entered)
|
||||
area.body_exited.connect(_on_area_body_exited)
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if pause_timer > 0.0:
|
||||
pause_timer -= delta
|
||||
else:
|
||||
progress += direction*speed*delta
|
||||
if !loop && (
|
||||
(direction > 0.0 && progress_ratio >= 1.0) ||
|
||||
(direction < 0.0 && progress_ratio <= 0.0)
|
||||
):
|
||||
progress_ratio = clamp(progress_ratio, 0.0, 1.0)
|
||||
direction *= -1.0
|
||||
pause_timer = pause_at_ends
|
||||
var velocity := (global_position - _prev_position).normalized()*speed
|
||||
_prev_position = global_position
|
||||
super(delta)
|
||||
if body:
|
||||
body.global_position = global_position
|
||||
body.constant_linear_velocity = velocity
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
class_name AutoPathFollow extends PathFollow3D
|
||||
|
||||
@export var speed: float = 1.0
|
||||
@export var pause_at_ends: float = 1.0
|
||||
|
||||
@onready var _prev_position := global_position
|
||||
|
||||
var _velocity := Vector3.ZERO
|
||||
|
||||
var direction: float = 1.0
|
||||
var pause_timer: float = 0.0
|
||||
var velocity: Vector3:
|
||||
get():
|
||||
return _velocity
|
||||
var paused: bool:
|
||||
get():
|
||||
return pause_timer > 0.0
|
||||
set(value):
|
||||
if value:
|
||||
pause_timer = INF
|
||||
else:
|
||||
pause_timer = 0.0
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if pause_timer > 0.0:
|
||||
pause_timer -= delta
|
||||
else:
|
||||
progress += direction*speed*delta
|
||||
if !loop && (
|
||||
(direction > 0.0 && progress_ratio >= 1.0) ||
|
||||
(direction < 0.0 && progress_ratio <= 0.0)
|
||||
):
|
||||
progress_ratio = clamp(progress_ratio, 0.0, 1.0)
|
||||
direction *= -1.0
|
||||
pause_timer = pause_at_ends
|
||||
_velocity = (global_position - _prev_position).normalized()*speed
|
||||
_prev_position = global_position
|
|
@ -0,0 +1 @@
|
|||
uid://dbbkfe87bos0n
|
Loading…
Reference in New Issue