This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I am writing a very small project and I use moveandslide to move my character. But somehow it feels very "lagging" (allthough on the FPS counter you can see that it isn't actually lagging). It looks as if it collides with something for quite a while and after some time somehow resolves the collision. In the example below I always press right all the time, then left all the time, then right all the time etc. The moments where he halts I do not let go of the movement key and keep it pressed until it moves again.
Here is a gif of the behaviour: https://giphy.com/gifs/L0rpubzitsYILpAptx/fullscreen
(I tried to inline it but I had no luck, sorry)
Does anyone know what could be wrong?

EDIT: Full project, zipped: https://files.fm/u/32dw9mtm
The part where I use moveandslide, in my KinematicsBody2D node:
`

var velocity = Vector2()
func _physics_process(delta):
    velocity.y += delta * GRAVITY

    if Input.is_action_pressed("ui_left"):
        velocity.x = -WALK_SPEED
    elif Input.is_action_pressed("ui_right"):
        velocity.x =  WALK_SPEED
    else:
        velocity.x = 0

    move_and_slide(velocity, Vector2(0, -1))``
in Engine by (31 points)
edited by

It's hard to tell you what may be wrong without seeing your code. Please post the code for the player where you're using move_and_slide().

thank you for answering, I edited my question

1 Answer

0 votes
Best answer

In the last line of code:

You:

 move_and_slide(velocity, Vector2(0, -1))

Solution:

velocity = move_and_slide(velocity, Vector2(0, -1))
by (192 points)
selected by

Thank you, I thought that moveandslide just does the "corrected" movement and does not needs to update the velocity. Your tip already helped, but now he randomly jumps. Does that mean that my collision shapes are not perfect and there are some small bumps on the ground?

You could check these things:

  • The collision shapes are in scale 1 by 1. You CANT scale the collision NODE. You have to use the inner handles to "scale" the size of the SHAPE (again, not the node) to your desire.

  • See if the shape you are walking has the bouciness 0.

  • How are you making the level collision shape? Collision shape to each tile? Check if there is no gap between the tiles. You can use pixel snape when "scaling" the shapes, so it will help to fit exactly your tiles (better if it is pixel art)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.