0 votes

I'm messing around in 3D with a modified FPS controller from the Asset Library and my gradual de-acceleration procedure is doing something confusing.
Here's a (pastebin) link to the only code in the scene, attached to a capsule-shaped KinematicBody resting on a simple StaticBody floor plane. When I look at the output, I can see compare_floats() being called almost constantly, but when I step through it in the debugger, I can't make sense out of why the program flows that way (that method should only be called when testing to see if the current velocity is close enough to 0 to just set at 0 and turn the de-acceleration procedure off). It seems to illegally contradict itself by executing the code on line 77 after the if velocity.x != 0 || velocity.z != 0: conditional. The debugger lists both of those values as 0, but the conditional still works out to true. I've tried replacing the 0 integer literal with 0.0 as well, but that had the same result.
Help understanding the control flow here would be great. Any suggestions on alternative ways to de-accelerate a moving KinematicBody after the user lets go of directional inputs (and the KinematicBody is on the ground, but that's an easy conditional to tack on) would also be helpful.

in Engine by (739 points)

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.