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

MoveAndSlide / IsOnFloor and MoveAndCollide don't work in C# scripts #19898

Closed
copygirl opened this issue Jul 2, 2018 · 8 comments
Closed

MoveAndSlide / IsOnFloor and MoveAndCollide don't work in C# scripts #19898

copygirl opened this issue Jul 2, 2018 · 8 comments

Comments

@copygirl
Copy link

copygirl commented Jul 2, 2018

Godot: 3.1.dev.mono.custom_build.896e250
OS: Arch Linux

Issue description

I tried following the FPS tutorial and recreate the 3D movement in a from-scratch project using C# scripts but I quickly ran into the issue of IsOnFloor() always returning false no matter what I tried.

MoveAndCollide also never returns a collision even though the entity stops as it collides with the floor.

Minimal reproduction project / Steps to reproduce

See the Player.cs file of my project.
Simply... let the player collide with the ground and see that the printed values stay false.

edit: It was suggested for me to increase the gravity, safe margin and check IsOnFloor() after MoveAndSlide(), so I did so, but still no luck.

edit2: I also tried re-implementing MoveAndSlide myself.

@ghost
Copy link

ghost commented Jul 2, 2018

Make sure your Floor Normal vector is actually pointing Up. Without specifying a floor vector the game won't know which way is up or down because by default is Vector3(0,0,0)

image
It needs to be Vector3(0,1,0) pointing UP

But even after you do this it will still not work properly. This is because move_and_slide attemps a number of slides and some of them will bounce off the ground which means your is_on_floor() is gonna look like true false true false true false ... alternating.

I suggest implementing your own method.

@copygirl
Copy link
Author

copygirl commented Jul 2, 2018

I've tried new Vector3(0, 1, 0), Vector3.Up (current) and Vector3.Down. The IsOnFloor() method at no point returns true, it appears. The FPS tutorial project doesn't have this problem. At this point I'm wondering if somehow the IsOnFloor binding isn't working at all.

@nadejin
Copy link

nadejin commented Jul 2, 2018

Try to call IsOnFloor after MoveAndSlide. Also increacing gravity acceleration and KinematicBody's safe margin seems to have effect on IsOnFloor behavior, you can play around and tweak. But still, none of this worked for me in case of colliding walls while standing on the floor, IsOnFloor seems to be flickering from true to false randomly. So I ended up replacing it with Raycast node until it's fixed, seems to be working well for now.

@copygirl
Copy link
Author

copygirl commented Jul 2, 2018

@int010h I tried what you suggested, but the changes still did not have an effect on the outcome. I will likely try to work around the issue like you recommended, though it was sort of important for me to report it.

@kubecz3k kubecz3k added this to the 3.1 milestone Jul 3, 2018
@jmf
Copy link
Contributor

jmf commented Jul 4, 2018

This seems to be a general issue with IsOnFloor() in the mono build. It doesn't appear to work at all. I was able to replicate this bug with 3.0.4-mono from the website. This bug doesn't seem to affect the is_on_floor() function in gdscript.

@copygirl
Copy link
Author

copygirl commented Jul 5, 2018

I tinkered around a little bit, re-implementing MoveAndSlide in C# and found out that MoveAndCollide never even returns a collision, yet stops the player from moving any further.

I might look into doing the same for MoveAndCollide but I'm not sure yet as I haven't taken a look at it; it's probably a bit more complicated than the other method. (edit: The function body_test_motion doesn't appear to have a C# binding so this doesn't appear possible.)

@copygirl copygirl changed the title IsOnFloor not affected by MoveAndSlide (3D) MoveAndSlide / IsOnFloor and MoveAndCollide don't work in C# scripts Jul 10, 2018
@RySchmitt
Copy link
Contributor

RySchmitt commented Nov 2, 2018

I think this caused by #5910. When building a first person controller, I ran into this exact issue in C#, but I was able to fix it by changing the collision shape of the floor from a PlaneShape to a CubeShape. I downloaded @copygirl 's project and the same change, with a couple tweaks, fixed the issue. The FPS tutorial in GodotScript also breaks if the floor is turned into a plane. It seems that the problem has nothing to do with the C# implementation.

I believe this issue should be closed.

@akien-mga
Copy link
Member

Closing as duplicate of #5910.

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

8 participants