Error in the script "The identifier "move_and_slide" isn't declared in the current scope

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

var score : int = 0

var speed : int = 200
var jumpForce : int = 600
var gravity : int = 800

var vel : Vector2 = Vector2()

onready var sprite : Sprite = get_node(“Sprite”)

func _physics_process(delta):

vel.x = 0

if Input.is_action_pressed("move_left"):
	vel.x -= speed
if Input.is_action_pressed("move_right"):
	vel.x += speed

move_and_slide

Im trying to use the move_and_slide function in my Kinematic2D script but it raises an error. Please help me clarify this doubt as I am new to Godot thanks.

:bust_in_silhouette: Reply From: aXu_AP

Double check which node the script is attached. In the beginning, extends CollisionShape2D tells that it isn’t in KinematicBody2D, but it’s collision shape. Try detaching the script from that node and attach it to the body (and change the first line correspondingly).

Also, I’m not sure if you omitted that part intentionally, but I’ll say it anyway: move_and_slide needs speed as a parameter: move_and_slide(vel)

Thank you so much, it works fine now.

sohm14 | 2022-12-12 18:03