0 votes

I'm in a hard situation. To manage movement in monster and players, I use a RigidBody2D with no friction. Because of that I need to set it's X velocity to 0 every frame when not walking. But that means I can't apply other forces to it, because it's gonna be set to 0. How did you manage it in your game? I'm thinking in creating an array of forces to be applied every frame, is that the best option?

in Engine by (1,119 points)

If you want to apply forces to your player/monster and don't want it to move, resulting forces in the direction of movement must be zero. It's Newton's second law consequence.
Why don't simply change your player concept and leave it move with friction? If no friction, the the player has to be stopped by user interaction (i.e. a button/action to stop it)

For monster I wouldn't use RigidBody2D, better KinematicBody2D

Don't set it's X velocity to 0 every frame. If you want the character to stop instantly when not walking you should be able to apply an appropriate force in the opposite direction once to stop it. Or if you're OK with it taking a little time to stop, just make your own friction/damping. I assume you're detecting when the characters are on the ground or not. When it is on the ground and not walking, apply a force to stop it, (-velocity.x * mass * k(damping coefficient)). Adjust k until it's as slidy/sticky as you want.

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 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.