add collision exception with not working with same PhisicsBody objects

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By linuxfree
:warning: Old Version Published before Godot 3 was released.

here my script i tryng do no collision with this 2 objects bu no have sucess

extends RigidBody2D # this is a enemy

var rock_large = preload(“res://rocks/rock_scene.scn”).instance() # a scene rock loaded

var duraRock = 20
var points = 500

var loop_anim = 0
var timeElapsed = 0

func _ready():
set_fixed_process(true)

 apply_impulse(get_pos(), Vector2(0, 0))
 set_angular_velocity(rand_range(0, 0))
 set_gravity_scale(0)

func _fixed_process(delta):
do somenthing…

if (Globals.has(“gameStarting”)):
print(“duraRock do inimigo :”, duraRock)

 get_node(".").add_collision_exception_with(rock_large.get_node("RigidBody2D"))

if (Globals.get(“gameStarting”) == false):
get_node(“.”).queue_free() # delete all node if not Started

 if (duraRock == 0):
    if Globals.has("score"):
       Globals.set("score", Globals.get("score") + points) 
       get_node(".").queue_free() # delete all node

this line → get_node(“.”).add_collision_exception_with(rock_large.get_node(“RigidBody2D”))

no have efect please help me

:bust_in_silhouette: Reply From: genete

rock_large is just a instance of a scene. It is not in the scene tree or visible on viewport. You should add the collision exception with an actual rock instance (wherever it is created).

Easier way is to use layer and collision masks for collision exceptions. Better do it on editor and not by scripts.

Two bodies collides if both layer and collision masks are the same. If you change the rocks’s layer (collision) mask to something different compared with enemies’s collision (layer) mask they wouldn’t collide.

See:

https://forum.godotengine.org/4010/whats-difference-between-collision-layers-collision-masks?show=4010#q4010

https://forum.godotengine.org/3020/collision-masks-and-its-propper-uses?show=3020#q3020

it worked! more fast :wink:

thanks

linuxfree | 2016-08-20 23:41