godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.12k stars 69 forks source link

Prevent CharacterBody3D from sliding because of snapping regardless of stop on slopes #9255

Open yosoyfreeman opened 6 months ago

yosoyfreeman commented 6 months ago

Describe the project you are working on

General physics improvements.

Describe the problem or limitation you are having in your project

AS seen here we are only making sure the snapping does not degrade the horizontal position only if stop on slopes is true.

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

Snapping is not the result of movement or sliding but a direct modification of the placement of the body, as such stop on slopes has no relation with it and the body should always try to keep its horizontal place when a snap is performed.

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

Remove the stop on slopes check and always make sure the new position is only altered along the up direction.

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?

Because is the expected behavior.

yosoyfreeman commented 6 months ago

I just noticed that p_cancel_sliding is not set to true on the parameters of the snapping function and that's why brute forcing the position after the collision resolution is made is necessary in first place. If p_cancel_sliding is set to true a more accurate resolution should take place rendering this part unnecessary.

Edit: Note that the current fix does not take into account the depth of the penetration while p_cancel_sliding does, so currently even with the correction the body could end up stuck in something and being depenetrated the next frame anyway, causing a sliding.