if is on wall script

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

plz can anyone help my this is the script

extends KinematicBody2D

var motion = Vector2()
var speed = 150
var gravity = 100
var dir = -1

func _ready():
pass

func _process(delta):
motion = move_and_slide(motion,Vector2.UP)
pass

func _physics_process(delta):
motion.x = speed * dir
if is_on_wall():
dir *= -1
$Sprite.flip_h = !$Sprite.flip_h
if is_on_floor() == false:
motion.y += gravity
pass

the problem here the enemy gliching in the wall and go left and right in the same place
What should I do ?

One suggestion: move the code motion = move_and_slide(motion,Vector2.UP) to the _physics_update() function, since that’s where the collision calculations are performed.

Ertain | 2022-11-11 04:48

thank you very much but i change the code

motion = move_and_slide(motion,Vector2.UP)

to

_physics_update()

but it say error Maybe I don’t understand what you mean

error(14,1): the method “_physics_update” isnt declared in the current class

dbldbli | 2022-11-11 08:50

:bust_in_silhouette: Reply From: kareem_farrag

_physics_update():
motion = move_and_slide(motion,Vector2.UP)