+4 votes

Sometimes when my character is walking on the floor, it appears like there is some sort of invisible bump on the floor. If i turn character mode on, the player stops moving when hitting that ''rough'' spot on the floor, when on rigid mode, it rotates like if it's hitting a bump. The collision boxes for the tileset and the player are completely straight.

I can't understand what the problem with this is.

in Engine by (26 points)

Is there a reason you couldn't use a kinematic body for your player instead?

Yes, the player is supposed to have the same physics as all the objects in the game. In fact it's on rigid mode instead of character.

What method are you using to update the movement? Do you have a code sample?

The left-right movement is pretty simple, it's constant, no acceleration as for yet. Nothing but this simple 4 lined code:

if Input.is_action_pressed('ui_right'):
        motion.x = SPEED
elif Input.is_action_pressed('ui_left'):
        motion.x = -SPEED

3 Answers

–3 votes

The docs advise against the use of RigidBody2d for your character and if you still wish to use it, you should not simulate movement by changing the position of the object..

[...] if you do wish to have some control over the body, you should take care - altering the position, linearvelocity, or other physics properties of a rigid body can result in unexpected behavior. If you need to alter any of the physics-related properties, you should use the _integrateforces() callback instead of physicsprocess().

see http://docs.godotengine.org/en/3.0/tutorials/physics/physics_introduction.html#rigidbody2d

Instead you would be much better off using KinematicBody2D for your character and movement.

See Using KinematicBody2D and Kinematic Character (2D)

Hope that helps.

by (76 points)

I'm not making a standard platformer, i want my character to behave like a normal object affected by the same physics as all the other rigid bodies in the game, so that's why i made it a rigid instead of a kinematic.

+3 votes

Are you using a TileMap? Tiles each have individual collision shapes which creates problems with collisions, from what I understand. When your character collides with the floor where two tiles are touching, you will often get two collisions. One of these will be with the corner of one of the tiles! The normal of that collision will be very different from the floor normal (often 0,-1).

Another way to test and see this is to have a RigidBody2D with bounce = 1 and a CircleShape2D as collision shape, and just look at it bounce on your TileMap floor: it will often do a bad bounce for no apparent reason. With Debug -> Visible Collision Shapes you will see two red dots (collisions) because it collides with two tiles: the top of one and the corner of the other. I have no idea how to fix this ATM. I hope I'm getting something wrong...

by (28 points)
0 votes

The character is getting stuck or rotating because you are using a rectangle collision shape and the sides of the lower corners of the rectangle are colliding with the sides of the upper corners of the floor (since tileset collisions create several square shapes). A workaround for this is using circle shapes for the feet of the caracter.

by (18 points)

I forgot about capsuleshape. It should be ideal to solve this problem since it gives you a roughly rectangular shape for the character but with round feet.

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.