0 votes

Not sure if there is some better way of handling this problem.

I have player controlled RigidBody2D. When falling and trying to run to the right or left, the velocity in the X component is killed when I get it from state.get_linear_velocity().

This makes for some stuttering on landings. slide() can't help either since the collision detection is doing this in between _integrate_forces(). What is the ideal way of working around this, am I overlooking something?


My current thoughts are that either I should never use get_linear_velocity(), or split out player movement, comparing and restoring any lost velocity frame by frame. Anyone have any insight into this problem or better solutions?

in Engine by (5,232 points)

Are you using state.set_linear_velocity() to control the character? Have you tried setting friction on the RigidBody2D to 0?

Yep friction is 0, sorry didn't mention that. It is a stuttering, the movement will continue from 0. The other changed properties are:

Continuous CD = RayCast
Can Sleep = false

Though it doesn't feel quite right, I'm working around in a way something like pseudo code below:

var prev_lv = Vector2()

func _integrate_forces(state):

    var curr_lv = state.get_linear_velocity()

    if(curr_lv.length() < 1.0 and prev_lv.x >= X_THRESHOLD):
        curr_lv.x = prev_lv.x

        # ... custom gravity, friction, etc.

    prev_lv = curr_lv

One thing I noticed is that if I set x-velocity with setlinearvelocity() but use the default RigidBody2D gravity and have continuous CD set to ray, I get a weird stutter when the character lands. If continuous CD is off or set to shape there's no stutter. If I turn custom integration on and apply gravity myself I sometimes get the stutter with continuous CD set to ray, depending on gravity strength. The other CD modes, no stutter. Try turning continuous CD off and see if it makes any difference.

I seem to get the odd little hitch no matter what I do. I can check for just landed and restore the X velocity, but there still are oddities in the sprite positioning. It seems to be ejected out 30 pixels or so for a frame. So the character art will still jolt about on landing.

I was considering casting a shape motion query, but then there is no obvious way to move a RigidBody without sleeping it, which will be a delayed frame too.

I would prefer to stick with a RigidBody, because of the easier interaction with other RigidBody nodes in the scene, but these results are looking quite bad at the moment. :(

Seems to be an issue with circle collision shapes and rectangles, but certain capsules work fine. Though the sprite is still jerked about.

Please log in or register to answer this question.

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.