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

Implement is_inside_solid_geometry() in CharacterBody #3066

Closed
Tracked by #50732
TokageItLab opened this issue Jul 31, 2021 · 4 comments · Fixed by godotengine/godot#64195
Closed
Tracked by #50732

Implement is_inside_solid_geometry() in CharacterBody #3066

TokageItLab opened this issue Jul 31, 2021 · 4 comments · Fixed by godotengine/godot#64195
Milestone

Comments

@TokageItLab
Copy link
Member

TokageItLab commented Jul 31, 2021

Describe the project you are working on

3D Character Game

Describe the problem or limitation you are having in your project

It is not possible to determine whether a CharacterBody is buried in objects or not. This means that it is not possible to get the object in which the CharacterBody is buried.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

If a CharacterBody is buried in an object, you can disable the collision of the object by checking is_inside_solid_geometry() to prevent it from getting stuck.

See also #3065.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Add a method to CharacterBody. I think it can be considered buried if the collision cannot be resolved after a user-set number of slides.

If this enhancement will not be used often, can it be worked around with a few lines of script?

No

Is there a reason why this should be core and not an add-on in the asset library?

It needs to be included within the GodotPhysics

@Calinou
Copy link
Member

Calinou commented Jul 31, 2021

The is_buried() naming seems strange to me. Why not is_stuck() or is_inside_solid_geometry()?

@TokageItLab TokageItLab changed the title Implement is_buried() in CharacterBody Implement is_inside_solid_geometry() in CharacterBody Jul 31, 2021
@TokageItLab
Copy link
Member Author

Since I am not a native English speaker, I consider the ones you mentioned to be better. For now, I'll change it to is_inside_solid_geometry() in the overview, which could explain the function.

@pouleyKetchoupp
Copy link

That could be useful, but I would rather do it in a more generic way.

Instead of a specific function, it should be possible to get the depth from any collision that occurred in your last character motion, by adding an extra function to KinematicCollision3D.

The information is already there, just not exposed to script. I can make a PR next week, but if you'd like to try it yourself, it should be easy to do.

You just need to add a new method get_depth() here that returns result.collision_depth, and add it to the script bindings too:
https://github.com/godotengine/godot/blob/20d46c5b9ede7bfb9001d341ac20d8a30f49cba5/scene/3d/physics_body_3d.cpp#L1446-L1460

That would allow your script to check if the depth is over a threshold and detect that your character is stuck.

@TokageItLab TokageItLab added this to the 4.0 milestone Aug 7, 2022
@TokageItLab TokageItLab moved this to In Discussion in Godot Proposal Metaverse Aug 7, 2022
@TokageItLab
Copy link
Member Author

TokageItLab commented Aug 10, 2022

I confirmed that this can be solved with the API already in place.

move_and_slide()
is_inside_solid_geometry = test_move(self.transform, Vector3.ZERO)

However, if there is get_depth(), it can be used for post-penetration test resolution, so I will send a PR later. In fact, MotionResult::collision_depth exists in KinematicCollision2D internally, so I think the port to KinematicCollision3D is simply not done.

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

Successfully merging a pull request may close this issue.

3 participants