"The function 'move_and_slide()' returns a value, but this value is never used" It is showing that when I run my game

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

extends KinematicBody2D

var motion = Vector2()

func _physicsprocess(delta):

if Input.is_action_just_pressed("ui_right"):
   motion.x = 100

elif Input.is_action_just_pressed("ui_left"):
	 motion.x = -100
else:
	motion.x = 0

move_and_slide(motion)
pass
:bust_in_silhouette: Reply From: Wakatta

Not so much an error but more of a reminder
If you’re pretty sure that you will never use that velocity information you can ignore it.

In the script editor to the bottom right of the script window click the yellow caution icon and then ignore

# warning-ignore-:return_value_discarded
    move_and_slide(motion)

Or

var _velocity = move_and_slide(motion)

You are right man but when I run my game it is not a reminder it is an error and it does not slide it just stays there

GodotMan | 2021-12-05 07:02

func _physicsprocess(delta):

    if Input.is_action_pressed("ui_right"):
       motion.x = 100

    elif Input.is_action_pressed("ui_left"):
       motion.x = -100
    else:
      motion.x = 0

    motion = move_and_slide(motion)

I suggest not reinventing the wheel with such simple things like movement and just looking up a tutorial to see how most people do it.

timothybrentwood | 2021-12-05 13:44

I was watching tutorial of GD quest he wrote this but for me it was not working!!!

GodotMan | 2021-12-07 02:41