So, i followed a tutorial on a platformer game and my enemy character glitched, how do i fix it

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

Here the enemy script

the script if from heart beast

extends KinematicBody2D

var direction = Vector2.RIGHT
var velocity = Vector2.ZERO

onready var ledgeCheckRight = $LedgeCheckRight
onready var ledgeCheckLeft = $LedgeCheckLeft
onready var sprite: = $AnimatedSprite

func _physics_process(delta):
	var found_wall = is_on_wall()
	var found_ledge = not ledgeCheckRight.is_colliding() or not ledgeCheckLeft.is_colliding()
	if found_wall:
		direction *= -1
	sprite.flip_h = direction.x > 0 
	velocity = direction * 25
	move_and_slide(velocity, Vector2.UP)

Edited to fix code formatting. Please use the {} button to properly format code for the forum. Otherwise, it’s really hard to read.

Regarding the problem, what do you mean when you say glitched? What is your character doing or not doing?

jgodfrey | 2023-02-03 14:43

turns out the collision shape 2d did not reached to the legs, so in the end it glitched from left 2 right

ExpNeeded | 2023-02-04 05:02

:bust_in_silhouette: Reply From: phteven

Hard to understand what you mean by glitched, but looking at the script in the video you’re missing a little bit in your if statement

it should read:

if found_wall or found_ledge:
    direction *= -1

Hopefully that helps