0 votes

I have an enemy and when it hits a wall it changes its direction, but it also happens with the player
I would like the clash with the player not to change the direction

How could I fix it

Script Enemy

 if is_on_wall():
            direccion.x = 1 if direccion.x == -1 else -1
in Engine by (93 points)

This question is much more clear and understandable than the other 2 mentioned. But you should avoid spamming anyway. Maybe editing would've been a better.

1 Answer

0 votes

You could go through all the collisions and skip direction change if the player is the only colliding body.
There is an example of how to do it in the docs: https://docs.godotengine.org/en/3.1/classes/class_kinematicbody2d.html#class-kinematicbody2d-method-get-slide-collision

by (572 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.