0 votes

I have a MovableBox scene, which is supposed to be a box that the Player can move when walking against it. This works, but despite the weight being high and the friction being at the highest setting, this box moves way too fast when a user walks against it.

The MovableBox is a RigidBody2D and the Player is a KinematicBody2D. I'm open to changing the MovableBox type (I tried StaticBody2D, but as the name implies, this should not be movable).

I also tried setting the "Mode" of he RigidBody2D to static, and moving the box "manually" when the player bumps into it by connecting the body_entered() signal of the MovableBox to itself, but the player walking into it is not detected for some reason.

I can share the project if needed.

Godot version 3.2.3
in Engine by (17 points)

1 Answer

+1 vote
Best answer

KinematicBody2D by default has infinite_inertia enabled. That means it pushes rigid bodies regardless of their physics properties. You need to set this to false in your move_and_collide() or move_and_slide() call(s).

More info:
https://docs.godotengine.org/en/stable/classes/class_kinematicbody2d.html#class-kinematicbody2d-method-move-and-collide

Example:
http://kidscancode.org/godot_recipes/physics/kinematic_to_rigidbody/

by (20,481 points)
selected by

Thank you very much. This is close to what I need. I can manage the speed as I want now, but I noticed that the movement is a bit choppy. I also notice this when downloading the example from your website. Is there a way I can make it smooth? I added a video to show what I mean. In the video, it looks a bit like the player gives the box a small push, catches up with the box, and pushes it again. Ideally, the player would be "stuck" to the box, pushing it in a smooth fashion.

Then there is another thing, the box becomes stuck after moving it a bit. Do you have an idea why this could be happening? I'm using a TileMap for the floor. You can see it right at the end of the video, the box is stuck and will not move in that direction anymore (the other direction works, until that gets stuck as well, after which changing directions is again possible)

video

The "choppiness" you're seeing looks like it's due to applying an impulse that pushes the box forward, but the friction seems to be stopping the box pretty quickly. It should be just a case of adjusting those properties so that they're not fighting against each other.

I don't really see the "stuck" issue, but it could be that your tile collisions are not perfectly aligned. The TileMap combines the tiles' collision shapes, and if they're not at integer values, there may be very tiny discontinuities there.

Thank you. I'll tinker with the friction a bit then.

The stuck issue is at the end. There, I keep pressing the move button, but the box is blocked.

I'm pretty sure that the tiles are aligned correctly, the tilemap uses 1 tile of 70x70, which I added using 4 35x35 blocks, as the image shows.

image

I found the problem, but don't know the solution. For some reason, collision shapes remain on the floor when moving the box, which sometimes cause a problem (see video). I solved it with a workaround, making the CollisionShape2D a capsule, resulting in a circular CollisionShape2D.

video

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.