You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
975 B
GDScript
37 lines
975 B
GDScript
|
2 years ago
|
extends Area3D
|
||
|
|
class_name PushBox
|
||
|
|
|
||
|
|
@export var pushbox_curve : Curve
|
||
|
|
|
||
|
|
@onready var character = (get_owner() as Character)
|
||
|
|
@onready var radius = $CollisionShape3D.shape.radius * scale.x
|
||
|
|
|
||
|
|
var pushbox_list = []
|
||
|
|
|
||
|
|
func _process(delta):
|
||
|
|
var speed_dir = character.get_status("speed_dir") as Vector2
|
||
|
|
if speed_dir.length() == 0:
|
||
|
|
return
|
||
|
|
var speed_down_push_rate = 0
|
||
|
|
var pos = character.pos2D()
|
||
|
|
for pushbox:PushBox in pushbox_list:
|
||
|
|
var target_pos = pushbox.character.pos2D()
|
||
|
|
var dir = target_pos - pos
|
||
|
|
if speed_dir.dot(dir) <= 0:
|
||
|
|
continue
|
||
|
|
var dist = dir.length()
|
||
|
|
if dist == 0:
|
||
|
|
continue
|
||
|
|
var dist_rate = clamp(dist/(radius+pushbox.radius),0,1)
|
||
|
|
speed_down_push_rate = max(speed_down_push_rate,pushbox_curve.sample(dist_rate))
|
||
|
|
character.set_status("speed_down_push_rate",speed_down_push_rate)
|
||
|
|
|
||
|
|
func on_area_entered(area:Area3D):
|
||
|
|
if area is PushBox:
|
||
|
|
pushbox_list.append(area)
|
||
|
|
|
||
|
|
func on_area_exited(area:Area3D):
|
||
|
|
if area is PushBox:
|
||
|
|
pushbox_list.erase(area)
|
||
|
|
|