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

move_and_collide yields inconsistent results when moving overlapping StaticBody3D #1001

Open
yosoyfreeman opened this issue Oct 15, 2024 · 8 comments
Labels
needs triage Something that needs investigation

Comments

@yosoyfreeman
Copy link

Hi! This one is kind of weird to explain so i made a little video plus the reproduction files.

I noticed that, when using jolt, a simple trace down was failing sometimes. After battling with it a lot i been able to isolate it.

Notice how, when i press play, the body is usually reporting the collision with the floor. as soon as i move the upper body, it stops registering nothing. If i move it again it goes back.

2024-10-15.14-02-42.mp4

This is a much of a "reproducible" setup as i was able to make. But this happens in my project under seemingly aleatory reasons just as in this demo. The thing it confuses me is that it seems to be a perfect "On off" every time i move it.

I confirmed that this behavior is not present in Godot physics.

Reproduction project:
(The 25 mb file size makes impossible to provide the reproduction project, as jolt + a script + a scene is already over that size in a .zip)

I have to provide the MRP without jolt. Please, add the last stable version.

joltbug.zip

@github-actions github-actions bot added the needs triage Something that needs investigation label Oct 15, 2024
@yosoyfreeman
Copy link
Author

Excuse the double post, but just confirmed that this doesn't happen in 0.12.0 stable.

@mihe
Copy link
Contributor

mihe commented Oct 17, 2024

Excuse the double post, but just confirmed that this doesn't happen in 0.12.0 stable.

I haven't had a chance to look into this, but are you saying that you were able to reproduce this in 0.11.0-stable but not in 0.12.0-stable?

@yosoyfreeman
Copy link
Author

yosoyfreeman commented Oct 17, 2024

Excuse the double post, but just confirmed that this doesn't happen in 0.12.0 stable.

I haven't had a chance to look into this, but are you saying that you were able to reproduce this in 0.11.0-stable but not in 0.12.0-stable?

Excuse me. I meant that is reproducible on the latest stable version (0.13.0) but not in the one before (0.12.0), so the problem has probably been introduced in the latest release.

@mihe
Copy link
Contributor

mihe commented Oct 17, 2024

Ah, that makes more sense. I'm not sure why I didn't read it as such. I'll take a look.

@mihe mihe changed the title Inconsistent move and collide behavior when the body is partially in touch with a floor. move_and_collide yields inconsistent results when moving overlapping StaticBody3D Oct 17, 2024
@mihe
Copy link
Contributor

mihe commented Oct 17, 2024

It does seem like this has something to do with the fact that you're moving a StaticBody3D. If you change Box3 to instead be an AnimatableBody3D you'll find that the collision is consistently reported.

Intuitively this makes some kind of sense to me, since the physics engine should be free to make all kinds of assumptions about a static body never actually moving, but the symptoms presented here are undoubtedly quite strange none the less.

I'll need to take a closer look at some later time as to what exactly is happening and whether this is a bug or just how it has to be. There have been other cases where Jolt has shown discrepancies with Godot Physics when it comes to moving static bodies, so I suspect this might just end up being another one.

@yosoyfreeman
Copy link
Author

Thank you for looking into it. I'm using an static body because i usually create my own character systems. As you can't directly inherit PhysicsBody3D and AnimatableBody3D already has some things i wouldn't like to interfere(It's thought as far as i know for platforms and similar things that try to apply impulses to other stuff). So the choice leaves me with StaticBody3D, which because it has all the movement methods minus the character related stuff thought would be a good choice. I'll keep and eye here, if this is how it must be, then i should probably open an issue pointing to the fact that we will not have a movable basic node to extend from in the future when we fully rely on Godot-Jolt.

Thank you for your time Mihe.

@mihe
Copy link
Contributor

mihe commented Oct 17, 2024

As you can't directly inherit PhysicsBody3D and AnimatableBody3D already has some things i wouldn't like to interfere(It's thought as far as i know for platforms and similar things that try to apply impulses to other stuff). So the choice leaves me with StaticBody3D, which because it has all the movement methods minus the character related stuff thought would be a good choice.

If you only want the absolute bare minimum of a kinematic body, you can do what AnimatableBody3D is doing already, which is inheriting from StaticBody3D and then overriding the body's motion type (or "mode") with PhysicsServer3D.body_set_mode(self, PhysicsServer3D.BODY_MODE_KINEMATIC) somewhere during its construction. It'll differ from StaticBody3D in the sense that it will actually have a linear/angular velocity when moving around, but frankly if you're actually colliding with other bodies you likely will want this anyway, since the collision response is somewhat odd/undefined otherwise.

if this is how it must be, then i should probably open an issue pointing to the fact that we will not have a movable basic node to extend from in the future when we fully rely on Godot-Jolt.

For what it's worth, this is somewhat of an issue in Godot Physics as well, where StaticBody3D won't always properly interact with things like Area3D because they're assumed to not be moving around much, or at the very least assumed to not be used for those types of gameplay elements. I wouldn't consider StaticBody3D a basic movable body in Godot Physics.

Frankly, I wish that KinematicBody3D hadn't been removed from Godot 3 and that instead it was made into exactly this, a bare minimum kinematic body, and that AnimatableBody3D and CharacterBody3D would inherit from KinematicBody3D instead. The fact that AnimatableBody3D inherits from StaticBody3D is somewhat strange to me.

@sinewavey
Copy link

sinewavey commented Oct 20, 2024

Hi, adding on to the above response.

I'm currently writing a custom engine module to deal with some similar issues as yourself.

So far, I've been able to get desired "total control" behavior from making a physics body 3D extension class, and in the constructor setting its mode to MODE_KINEMATIC as mihe mentions above. This is actually what CharacterBody3D does internally anyway:

VirtualBody3D::VirtualBody3D() : PhysicsBody3D(PhysicsServer3D::BODY_MODE_KINEMATIC) {... rest of ctor }

The setup is extremely minimal, and is basically only just a method bind or two beyond that. It perhaps can be offered as a custom build (as I don't think this could be merged reasonably into Godot itself). But hey, you can always try a proposal to re-implement a "neutral" interface.

In practice, I only plan to use this for one instance in a single-player game, so there's some assumptions made currently for my specific use, but it seems to play okay so far with the rest of Godot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Something that needs investigation
Projects
None yet
Development

No branches or pull requests

3 participants