0 votes

Create an enemy that changes direction when it collides with a wall, but I don't want that to happen shock with a player

if is_on_wall():
        direccion.x = 1 if direccion.x == -1 else -1
        $Spr.flip_h = false if $Spr.flip_h == true else true
in Engine by (91 points)

1 Answer

0 votes

I had a similar question when I was trying to make falling objects disappear instead of bouncing off the player when colliding. My solution was to put an Area2D inside of my "player" KinematicBody2D parent node with an Area2D collision slightly bigger than the KinematicBody2D collision. The Area2D collision boxes can behave differently than the KinematicBody2D/StaticBody2D/RigidBody2D ones in which it won't make them bounce back and you can detect what is colliding or entering the collision shape to make a something happen (disappear, shock, damage, etc). I recommend that you try using an Area2D with a CollisionShape2d as the child on your enemy character, and then connecting the area_entered() signal to your player character, to have damage or what ever you want to happen to either or both of them.

by (71 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 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 webmaster@godotengine.org with your username.