move_and_collide
will stop the motion once it hit's an obstacle. So as of now you already are discarding the remaining motion! To get rid of the warning, you would need to store the value that is returned by move_and_collide
like this:
var collision = move_and_collide(velocity * delta)
Which likely will produce another warning, as you're not using that value somewhere else. To get rid of that warning as well, you'd do:
var collision = move_and_collide(velocity * delta)
if collision:
pass
Now instead of just passing (i.e. doing nothing) when a collision occurs, you likely want to do something meaningful. The collision
-variable is of type KinematicCollision2D. You can use it to get more information about the collision, e.g.:
var collision = move_and_collide(velocity * delta)
if collision:
print("collided with: ", collision.collider.name)
print("(discarded) remaining motion: ", collision.remainder)
I would recommend you also read this tutorial carefully.
A few remarks on your code:
- Your
move_tween
uses a duration of 60 seconds! That seems very slow.
- You should only move KinematicBody2D in
_physics_process
, not process
.
- Setting
motion.y = 0
every frame is unnecessary, it is zero by default.
- The
delta
-argument of _process
contains the time passed since the last frame. The motion
-variable should be multiplied by it, to ensure the movement stays consistent even if frames are dropped. Take a look at my examples above.
- The second argument of
move_and_collide
is a boolean: infinite_inertia
. It's true by default, but you set it to Vector2.LEFT and Vector2.RIGHT
. Which is always true as well! So this is most likely not what you wanted to do.
- Because you're checking for input actions after you called
move_and_collide
, you are creating an input lag of one frame. Depending on your game, that might or might not be quite notable when playing through it.