Skip to content
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

KinematicBody2D is_on_floor() and is_on_wall() are refusing to return true on the same frame when using small vector values #46634

Closed
Tracked by #45334
rainlizard opened this issue Mar 3, 2021 · 3 comments

Comments

@rainlizard
Copy link
Contributor

Godot version: v3.2.4.rc3
OS/device including version: Windows 8.1
Issue description:

Untitled

extends KinematicBody2D
var motion = Vector2()

func _physics_process(delta):
	motion += Vector2(1,1)
	motion = move_and_slide(motion, Vector2.UP)
	
	for i in get_slide_count():
		print(get_slide_collision(i).collider.name)
	print('WALL COLLISION: ' + str(is_on_wall()))
	print('FLOOR COLLISION: ' + str(is_on_floor()))
	print('----------------------------------')

The Godot icon moves into the two walls, then prints this, flipping back and forth:

South Wall
WALL COLLISION: False
FLOOR COLLISION: True
----------------------------------
East Wall
WALL COLLISION: True
FLOOR COLLISION: False
----------------------------------

If you replace the line motion += Vector2(1,1) with motion += Vector2(5,5) they will now return true on the same frame. No idea what's going on.

Here's the minimal reproduction project:
physics_on_wall_on_floor_bug.zip

@pouleyKetchoupp
Copy link
Contributor

Thanks! I can confirm on both 3.2.3 and 3.2.4.rc3.

@Calinou
Copy link
Member

Calinou commented Jun 11, 2021

See Shfty's character movement manifesto for a workaround:

  • Unstable floor results make my 'is grounded' flag jitter
    • This seems to be down to the collision margin system
    • Use a rolling window (2-3 frames should be sufficient) that folds down to a single bool using OR to de-noise the floor check

@pouleyKetchoupp pouleyKetchoupp added this to the 4.0 milestone Oct 6, 2021
@pouleyKetchoupp
Copy link
Contributor

Fixed on master with the new CharacterBody logic (confirmed on 6877ccc but not sure which PR).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants