Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save realkotob/2a5643ee6e6d14310e9c78ba5f3e49d9 to your computer and use it in GitHub Desktop.
Save realkotob/2a5643ee6e6d14310e9c78ba5f3e49d9 to your computer and use it in GitHub Desktop.
extends RayCast2D
# If this is use to disable collisions
export(bool) var disable_collisions = false;
# What to set/remove collisions against
export(NodePath) var physics_path
var physics_object
func _ready():
print( "Physics object: "+ str(physics_path))
physics_object = get_node(physics_path)
add_exception(physics_object)
set_exclude_parent_body(true)
set_physics_process(true)
func setDisableCollisions(_disable):
disable_collisions = _disable
func _physics_process(delta):
if physics_object != null:
set_position(physics_object.get_position())
var collision_obj_to_add_back = []
while is_colliding():
var col = get_collider()
if col == null:
continue
#print("Ray with: "+ col.get_class())
if col != null && col is PhysicsBody2D :
#print("Setting collision: "+ str(disable_collisions) + " " + str(get_name()) +" "+ str(physics_object.get_name()))
col.propagate_call("setOneWayCollision", [disable_collisions, physics_object], true)
if !(col is Area2D):
collision_obj_to_add_back.append(col)
add_exception(col)
force_raycast_update()
for col in collision_obj_to_add_back:
remove_exception(col)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment