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

Allow apply_floor_snap to preserve the horizontal position regardless of stop_on_slopes #99397

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

yosoyfreeman
Copy link
Contributor

@yosoyfreeman yosoyfreeman commented Nov 18, 2024

Removes the stop_on_slopes check from apply_floor_snap, allowing the part of the code that preserves the horizontal position to work independently of the value of stop_on_slopes. This should provide a more consistent behavior and prevent the character from sliding along the horizontal axis as a result of what should be a pure vertical snapping.

Fixes godotengine/godot-proposals#9255

It would be technically more correct to set p_cancel_sliding on the parameters too, but it seemed like something for another PR.

EDIT:

@a0kami has made a test scene to make sure it is working as intended.

Pre-PR: The non stop on slopes has non vertical motion on the snapping, more noticeable incrementing safe margin a bit. You can notice how snapping those bodies cause a wrong horizontal motion. Note how the bodies still snap even if the safe margin is large enough to touch the platform, contrary to the stop on slopes bodies that will not try to snap the body if the distance to the floor is less than the safe margin.

pre-pr.mp4

After-pr: The snapping is now consistent between both types of bodies, the non stop on slopes bodies now snap correctly along the snapping vector, and the safe margin is being respected too.

After-pr.mp4

As you can see the different is quite noticeable and we are gaining a lot of precision.

TEST PROJECT BY @a0kami:

test.tar.gz

@yosoyfreeman yosoyfreeman requested review from a team as code owners November 18, 2024 15:11
@adamscott adamscott changed the title Allow apply_floor_snap to preserve the horizontal position regardless of stop_on_slopes Allow apply_floor_snap to preserve the horizontal position regardless of stop_on_slopes Nov 18, 2024
@yosoyfreeman
Copy link
Contributor Author

I have been just pointed out that there is an equivalent check in the 2D version. I'm not that familiar with the 2D engine but i will check it out and try to make the equivalent changes there too.

@yosoyfreeman yosoyfreeman requested a review from a team as a code owner November 18, 2024 21:07
@Chaosus Chaosus added this to the 4.4 milestone Nov 20, 2024
@yosoyfreeman
Copy link
Contributor Author

PR updated with videos of pre and post PR and a test project.

Copy link
Member

@rburing rburing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change makes sense to me. Indeed floor snapping should only move the body along the up axis. Any motion orthogonal to the up axis is from the "free the body if stuck" phase of body_test_motion. It should be fine to cancel that motion, because the previous (non-floor-snapping) move_and_collide (from the loop in _move_and_slide_grounded) already took care of freeing the body if stuck.

Edit: Something equivalent to the previous sentence should be added to the code comment as well.

Edit 2: I guess the original idea may have been to use the depenetration of the body to intentionally cause some sliding.

@yosoyfreeman
Copy link
Contributor Author

Thank you! I'll probably have some time tonight or tomorrow!

To be clear, as is my first PR in Godot:

  • Should i change the comment in the 3D node to match your new one on the 2D node? for coherence, also yours is clearer.

  • I should add a code comment explaining why we can safely cancel the motion, as you explained.

Are those all the changes needed or do i need to tackle something else?

Thank you again for your time!

@rburing
Copy link
Member

rburing commented Dec 5, 2024

Should i change the comment in the 3D node to match your new one on the 2D node?

Yes.

I should add a code comment explaining why we can safely cancel the motion, as you explained.

Yes.

Are those all the changes needed or do i need to tackle something else?

Those are all the changes, yes. Then please squash the commits. After that I think we can merge it.

@yosoyfreeman
Copy link
Contributor Author

Done! Hope i didn't messed up with squashing, kind of confusing, but i think everything is okay.

Copy link
Member

@rburing rburing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks for working on this!

@yosoyfreeman
Copy link
Contributor Author

Awesome! Thank you a lot for the assistance!

@Repiteo Repiteo merged commit b88fd31 into godotengine:master Dec 10, 2024
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Dec 10, 2024

Thanks! Congratulations on your first merged contribution! 🎉

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

Successfully merging this pull request may close these issues.

Prevent CharacterBody3D from sliding because of snapping regardless of stop on slopes
4 participants