Last active
July 22, 2019 15:02
-
-
Save Razzlegames/6510db11811c47a294ae9a50635ea96e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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