make player go through block but enemy cant

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MrGwasty

i want my player to be able to just go through a block like there is no collision but enemies cant and would just act like there is a collision there also i used this code to make my slime change direction


motion.x = speed * dir

move_and_slide(motion,Vector2.UP)

$AnimationPlayer.play("Slide")
if is_on_wall():
	dir *= -1
	$Sprite.flip_h = !$Sprite.flip_h
if is_on_floor() == false:
	motion.y += gravity

or if there is a way for my slime enemy to go the opposite direction if they see there is an edge and they are gonna fall off if they dont go the opposite direction

:bust_in_silhouette: Reply From: the_maven

In the Docs there is the Physics introduction:

Put each in a Layer, and make your character be in a layer that not interact if you block but the enemies do.

:bust_in_silhouette: Reply From: kidscancode

This is the perfect situation for collision layers and masks. For example, if you set the collision layer of the block to “block”, you can then set “block” on the mask of the player and disable it on the mask of the enemy.

More here: Physics introduction — Godot Engine (stable) documentation in English

For edge detection, you can use a Raycast2D pointed down (or two of them - one on each side of the enemy) and when it stops detecting anything, that’s when you know you’ve readched an edge.

thanks recasting is way easier to understand then collision layers tbh now i can finally have my slime not suicide

MrGwasty | 2022-07-15 16:40