This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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


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

Godot version 3.4.4
in Engine by (19 points)

2 Answers

+4 votes
Best answer

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:

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.

by (22,191 points)
selected by

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

+1 vote

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.

by (232 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.