How to stop raycast2d from deteting enemy coillision

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

I have two raycast to detect if my player has touched the ground but it detects all collision even on my enemies how can i make it so that it only will detect if i am touching the ground collison box.
here is my code for the raycast2d collision

func is_on_ground():
if raycast_down.is_colliding() or raycast_down2.is_colliding():
	return true

You can do this by changing your enemies collision layer. However their naming has changed in 3.0, which version of Godot are you using?

Zylann | 2017-12-26 10:38

i am using v2.1

Newby | 2017-12-27 23:24

:bust_in_silhouette: Reply From: Zylann

You can stop raycast from detecting enemies by moving enemies inside a different collision layer. So you will be able to tell your Raycast2D to only care about the environment (such as platforms and walls) and not enemies.

Take a look at the layer_mask and collision_mask properties, all physics objects have these.
They can be set in the editor, their property look like a bunch of checkboxes, each check box represents one layer.

The doc explains what collision layer and mask are: PhysicsBody2D — Godot Engine (stable) documentation in English