godotengine / godot-proposals

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

Add the option to stop KinematicBodies from sliding up steep slopes that exceed `floor_max_angle` #2974

Closed tomsaram closed 2 years ago

tomsaram commented 3 years ago

Describe the project you are working on

I am developing a 2D platformer game, where some walls are not perfectly vertical for platforming reasons.

Describe the problem or limitation you are having in your project

When the kinematic object calls move_and_slide() or move_and_slide_with_snap() on the floor, the slightly tilted wall is treated as a very steep slope. The object will just climb the wall instead of stopping.

Animation The intended behavior is for the object to stop at the steep slope.

Notice also a similliar phenomenon will happen if a slope id placed next to a vertical wall, if the velocity is rotated to match the slope.

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

Add another argument to move_and_slide() or move_and_slide_with_snap(), say stop_on_walls, which is a Boolean that if true, the moving object stops when colliding with a different type of surface (floor/wall/ceiling) instead of sliding.

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

Just call move_and_slide() or move_and_slide_with_snap() normally with the addition of the new stop_on_walls flag.

Behind the loop, I think the type of the colliding object (floor/wall/ceiling) can be calculated with its normal and floor_max_angle, and the sliding loop can be terminated immediately if the current collider type differs with the previous type (if there is any).

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

This can be achieved by moving backwards from the steep slope back to the floor by going through get_slide_collision(), comparing the normals one by one, and reverting to previous position.

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

This would be a minor modification to an existing function. No new assets will be introduced.

Calinou commented 3 years ago

cc @pouleyKetchoupp

Physics nodes have been reworked in 4.0, which means making move_and_slide() even more complex is likely not an option.

However, what you're describing sounds like a bug – search on the main Godot repository for possible duplicates.

tomsaram commented 3 years ago

cc @pouleyKetchoupp

Physics nodes have been reworked in 4.0, which means making move_and_slide() even more complex is likely not an option.

However, what you're describing sounds like a bug – search on the main Godot repository for possible duplicates.

@Calinou I did not find any bugs on going up a steep slope. And honestly I am not sure what is the intended behavior here and can't find it in documentations.

2blackbar commented 3 years ago

I agree,Some flags would help, slopes are pain in the butt to code against, theres so much things to learn just to get character walk properly on slopes, and different people have different code to patch that problem , IMO default behaviour from get go on slopes should be no sliding off and normal walkup/walkdown, if you want that juttery weird behaviour then just disable flags to have that... but who wants his char to jump randomly on slopes

fabriceci commented 2 years ago

This is implemented now in 4.0 by default with the option block on wall.