Hey
I making a endless 2d runner in the godot engine. All the mechanics work fine except the enemy one(you have to dodge them in order to survive).Basically I want to flip my enemy(like the sprite and the direction).The code below is the enemy script. it flips the character when needed. The one that detects cliffs using raycast works fine but whenever the enemy is on a wall if flips left and right simultaneously. Could anyone help me with that? Thank You
extends KinematicBody2D
export var direction : int = 1
var speed : int = 35
var velocity : Vector2 = Vector2.ZERO
func _ready():
$AnimatedSprite.play("idle")
if direction == -1:
$AnimatedSprite.flip_h = true
$RayCast2D.position.x = $CollisionShape2D.shape.get_extents().x * direction
func _physics_process(delta):
velocity.y += 20
if is_on_floor():
velocity.x = speed * direction
if is_on_wall() or not $RayCast2D.is_colliding():
direction *= -1
$AnimatedSprite.flip_h = not $AnimatedSprite.flip_h
$RayCast2D.position.x = $CollisionShape2D.shape.get_extents().x * direction
velocity = move_and_slide(velocity, Vector2.UP)