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.
|
|
|
|
extends Area3D
|
|
|
|
|
class_name Hitbox
|
|
|
|
|
|
|
|
|
|
@export var pushbox_curve: Curve
|
|
|
|
|
|
|
|
|
|
@onready var character: Character = (get_owner() as Character)
|
|
|
|
|
|
|
|
|
|
var radius: float
|
|
|
|
|
var pushbox_list: Array[Variant] = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
|
var collisionShape3D: CollisionShape3D = $CollisionShape3D as CollisionShape3D
|
|
|
|
|
var shape: CylinderShape3D = collisionShape3D.shape as CylinderShape3D
|
|
|
|
|
radius = shape.radius * scale.x
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _process(delta) -> void:
|
|
|
|
|
var speed_dir: Vector2 = character.get_status("speed_dir") as Vector2
|
|
|
|
|
if speed_dir.length() == 0:
|
|
|
|
|
return
|
|
|
|
|
var speed_down_push_rate: int = 0
|
|
|
|
|
var pos: Vector2 = character.pos2D()
|
|
|
|
|
for pushbox: Hitbox in pushbox_list:
|
|
|
|
|
var target_pos: Vector2 = pushbox.character.pos2D()
|
|
|
|
|
var dir: Vector2 = target_pos - pos
|
|
|
|
|
if speed_dir.dot(dir) <= 0:
|
|
|
|
|
continue
|
|
|
|
|
var dist: float = 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)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func on_area_entered(area: Area3D):
|
|
|
|
|
if area is Hitbox:
|
|
|
|
|
pushbox_list.append(area)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func on_area_exited(area: Area3D):
|
|
|
|
|
if area is Hitbox:
|
|
|
|
|
pushbox_list.erase(area)
|