Compare commits
2 Commits
ef54e30784
...
4510dd2293
Author | SHA1 | Date |
---|---|---|
|
4510dd2293 | |
|
478a871ee9 |
|
@ -1,35 +1,17 @@
|
|||
class_name AutoPathFollow 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
|
|
@ -1,6 +1,6 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://dsgofpf33wf3c"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bk4rnp6ytjley" path="res://props/auto_path_follow.gd" id="1_8irhf"]
|
||||
[ext_resource type="Script" uid="uid://bk4rnp6ytjley" path="res://props/moving_platform.gd" id="1_8irhf"]
|
||||
[ext_resource type="PackedScene" uid="uid://dkr18e7uct18e" path="res://models/props/platform_constructed.blend" id="1_nde2r"]
|
||||
|
||||
[sub_resource type="CylinderShape3D" id="CylinderShape3D_goegf"]
|
||||
|
|
|
@ -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