-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
isOnFloor is intermittently false when moving against the floor normal #16268
Comments
|
Thanks @volzhs I'll try that now Edit: Unfortunately the problem is still happening |
I also made an issue about this earlier in the day, see #16250. EDIT: That timing. You're good. |
@LikeLakers2 are you using GDScript? This is happening to me on C# |
@divmgl Yes I am. My example project is all GDscript. |
I not sure how can this can be solved with PhysicsServer. // Vertical jumping logic
if (isOnFloor) {
Velocity.y = 0.1;
isJumping = false;
isDoubleJumping = false;
} else {
Velocity.y += delta * GRAVITY;
GD.Print("not on floor, gravity: " + Velocity.y);
} |
@volzhs no this is not solved, I was simply misunderstanding the problem |
I remember an issue like this, is your safe margin the default 0.08? |
Hey @eon-s thanks for your response. I've tweaked the safe margin and I'm still getting this issue. |
You have to call ModeAndSlide() BEFORE IsOnFloor() or IsOnWall(). What happens is probably the following: the MoveAndSlide() functions set the internal attribute isOnFloor. Since you use MoveAndSlide() at the end of your function, the values are sometimes still usable for the next _process() call. But sometimes, a physics frame goes between two _process() calls which resets the values to 0. |
@groud I've updated the code and it's still happening. |
@divmgl Can you give us the new code ? |
I've removed the content folder so you may not be able to run it but it's essentially the same thing just different code. It's still happening. |
Instead of:
Could you try this ? :
|
@groud I'd like to propose that at the first time too. :) |
The movement of any |
No, it's needed only if you need synchronisation with the physics engine. Thus, with a KinematicBody it's not necessary. |
It is necessary. Notice that |
I changed |
I'm having a problem with it as well. It look like my The code is here. |
I recently ran into this issue as well. Seems like is_on_floor() doesn't work correctly unless a collision occurs with the floor. So I had to apply a |
@justinluk You are the man, saving the day |
My working hypothesis on this is that if move_and_slide() and is_on_floor() are called when the latter would return null, then you will have unexpected behavior using that returned value in control flow. The is_on_floor() function may return null if called out of sync with the physics engine, per previous comments.
This works for me, but isInFlight must have greater scope than the method it's written in, so it's data is remembered during the next _process() call. It's too early for me to tell if this solution works in all cases, hence my hypothesis. Another advantage of my approach is that I avoid introducing unexpected data into my script because I don't use an external function's data for anything except validation. I don't trust functions I don't write myself. :P |
It’s impressive that two years after the fact this is still a problem. I’ve since moved on from Godot.
While in general I’d agree with this, the point of a solution like Godot is that you can focus on the product and less on the boilerplate code. |
Since I had this problem recently (and this issue seems to get some traffic,) I figured I'd spend a few days looking into it. The bad news is, I don't see an easy fix in the engine. The good news is, it's very easy to fix in your code. The short solution is simple, per @justinluck. Instead of having a movement loop like this:
Use a loop like this:
This will make it so you'll always have some downwards velocity on the ground, causing a collision with the floor and ensuring That's enough to fix the bug. For the curious, I've attached a longer explanation below. The key to this bug is that objects start every motion by pushing themselves out of collision distance of all other objects. However, this only happens when the first object is moving. That object is then moved along its intended path as much as possible before it actually overlaps with another object. Say you're using the first loop above (the bad one). On the first frame of your game, Once you start moving, though, the engine snaps awake and kicks you out of the floor. Here's the kicker: if your motion is perfectly horizontal, well, you won't move downwards. This leaves you just out of collision distance with the floor, causing I've honestly got no idea how this would be fixed (and it probably shouldn't be). One idea is to only kick a collider out of a body if it isn't moving parallel to said body . I've tested this, and although it removes the issue in a vacuum, it comes back when you're colliding with another object (i.e. running into a wall.) |
Hey there, I've run into this Problem just today and found an easy solution. The Problem...is a physical one. I guess you aren't implementing force and inertia of mass.
The FixesHard way Easy way if is_on_floor():
movement.y = -0.1
else:
movement.y -= GRAVITY * delta |
EASY FIX: if grounded: |
If you implement gravity your character is actually at Setting your
The real question is: What is actually needed?
|
Posting here after encountering exactly the same issue in Godot 3.2.2 (C#/mono) and finding this thread. The fix for me was to replace my existing motion vector with the output vector from var motion = Vector2.Zero;
// manipulate motion - including resetting motion.y to 0 when hitting the floor
MoveAndSlide(motion, Vector2.Up); Instead: var motion = Vector2.Zero;
// manipulate motion - don't set motion.y to 0, MoveAndSlide will handle floor collision
motion = MoveAndSlide(motion, Vector2.Up); |
If you set the velocity.y to be 0 when isOnFloor, then change it to 1 or something positive, in that way it will detect the collision. |
Nope. Up till now, version 3.2.3 stable, still having the same issues. After searching up the entire web for a solution, none. I'm using this function on 3d so im guessing something in code has a problem with it. My animations glitches when using the function. Results alternate between true and false 10 times when colliding. Definitely a system bug. |
Being new to github and all, i'm not even sure if they closed the issue and left it. How am I to know whether they are actually trying to fix this? |
Try upgrading to 3.3rc9 and see if you can still reproduce the issue there. (Make a backup of your project before upgrading.) Also try switching the 3D physics engine GodotPhysics in the Project Settings.
This issue was closed by its author, not by a maintainer. There's #35780 which is still open. |
try to use move_and_slide_with_snap(x,y, Vector2.UP) |
Godot version:
3.0, C# with Mono
OS/device including version:
Windows 10, GTX 1080
Issue description:
KinematicBody2D.IsOnFloor()
is intermittently false when moving against the floor normalSteps to reproduce:
Minimal reproduction project:
peridot.zip
I've already set the
FLOOR_NORMAL
when usingMoveAndSlide
, so there's no reason as to why this should be happening.The text was updated successfully, but these errors were encountered: