18 lines
685 B
GDScript
18 lines
685 B
GDScript
class_name HitscanRay
|
|||
|
|
extends RefCounted
|
||
|
|
static func cast(p: Fighter, start: Vector3, end: Vector3, mask: int) -> Dictionary:
|
||
|
|
var ray := p.get_node_or_null("HitscanRay") as RayCast3D
|
||
|
|
if ray == null:
|
||
|
|
ray = RayCast3D.new()
|
||
|
|
ray.name = "HitscanRay"
|
||
|
|
ray.enabled = false
|
||
|
|
p.add_child(ray)
|
||
|
|
ray.add_exception(p)
|
||
|
|
ray.global_position = start
|
||
|
|
ray.target_position = ray.to_local(end)
|
||
|
|
ray.collision_mask = mask
|
||
|
|
ray.hit_from_inside = true
|
||
|
|
ray.force_raycast_update()
|
||
|
|
if not ray.is_colliding(): return {}
|
||
|
|
return {"position":ray.get_collision_point(), "normal":ray.get_collision_normal(), "collider":ray.get_collider(), "rid":ray.get_collider_rid(), "shape":ray.get_collider_shape()}
|