0 votes

In Godot 3.1 Beta 1 the moveandslide function of a KinematicBody2D Node only works when the Node has a CollisionShape as child. But what is if I don't want to have a collision?

in Engine by (22 points)

1 Answer

0 votes

If you don't want collisions, there is practically no reason to use KinematicBody2D, because without shape, the body has no "existence" in the physics world.

If you don't need collisions, these two lines do the same:

    # If you want collisions
    move_and_slide(Vector2(100.0, 0.0))

    # If you don't want collisions
    position += Vector2(100.0, 0.0) * delta
by (28,744 points)
edited by

Ok this makes sense but I'm not able to get a smooth flappy bird like movement without the move and slide function.
Can you give me a short hint to get a smooth movement without the move and slide function?

What move_and_slide does without anything to slide on would be this:

position += delta * velocity

Where velocity is a vector you choose for the speed in pixels per second in X and Y, and delta the parameter of the _physics_process function in seconds.

I'm not sure what you mean by move_and_slide not working though. In your case it's very easy to workaround as you see, but I wonder if that was intentional.

There are two different situations:
First situation is that I press a button for e.g. 5 seconds and then the player moves with a constant speed as long as the button is pressed. This works fine.

The second situation is that I press a button just once (not holding it pressed) and then the player "jumps" (like in flappy bird) but the problem here is that player directly teleports to the new position.

If it teleports at new position there is probably something wrong with your code, even if you used move_and_slide. In a flappy bird game, the "jump" is usually implemented by modifying the velocity, not directly the position (which should be modified every frame in _physics_process, using either move_and_slide or the formula I posted.

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 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 webmaster@godotengine.org with your username.