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

add reapply_lost_speed to KinematicCharacterController #569

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ntibi
Copy link

@ntibi ntibi commented Dec 17, 2023

Adds reapply_lost_speed: bool to KinematicCharacterController

When set to true, the velocity lost by sliding will be reapplied to the corrected direction
so the character moves at the same speed wether it's sliding or not

Comment on lines 275 to 320
if self.slide && self.reapply_lost_speed {
let diff =
pre_slide_translation_remaining.norm() - translation_remaining.norm();
if let Some((normalized_dir, _)) =
// threshold has to be > subtract_hit hardcoded correction, if not, we get made up movement in the direction of the hit normal
UnitVector::try_new_and_get(translation_remaining, 1.0e-4)
{
// reapply the lost speed (but in the corrected direction)
translation_remaining += *normalized_dir * diff;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

That condition should probably be in case there is no stairs ? otherwise we might end up intersecting with the stair. (and it might result in not going up the stair, or worse an infinite loop ?)

Copy link
Author

Choose a reason for hiding this comment

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

indeed, but even with the reapply in the if !self.handle_stairs, reapplying the speed can be slightly flaky, especially in 3d

im turning the PR back into a draft and looking into it

@ntibi ntibi closed this Aug 3, 2024
@ntibi ntibi force-pushed the kcc_reapply_lost_speed branch from 0c8a7c0 to 617428e Compare August 3, 2024 11:37
@ntibi ntibi reopened this Aug 3, 2024
@ntibi ntibi marked this pull request as draft August 3, 2024 12:44
@MeFisto94
Copy link

MeFisto94 commented Jan 10, 2025

I guess kind of reworking the controller to not have the speed loss in the first place is not really possible? Would that result in loads of loop iterations of the slope sweeps?

I am asking because technically this behavior of slowing down/speeding up on slopes is not what one would expect from a character controller, especially contradicting the "kinematic" keyword. Same as the concept of "friction", it should usually always be infinite or zero.

For slopes specifically, the expectation (subjectively) is that one can climb them at full speed and descend them at full speed, unless the angle exceeds the maximum angle, then slipping is involved in some way.

My problem currently also is that I can't control which slopes to climb as the effect of the slope angles is too high, while also causing considerate CPU load (the loop that does the offset by the normal nudge and then raytraces again).

So, TLDR: This sounds like it solves problems of an actual dynamic character controller, not a kinematic one and properly getting that kinematic behavior may involve going back to the drawing board

Edit: Maybe it's a "simple" matter of gravity as well, because when I stopped applying gravity to the "input", I got a much better behavior at sliding (of course you can't drop down then), but obviously that fails on downward slopes. I'll try to see if I can do something about that just by conditionally having gravity on when not on ground or something.

Edit 2: The more I think about it it's related to manually applying gravity (I sure hope I copied that from some example), because the code in handle_slopes talks about the users intent based on the vertical component of input. For a character controller (and not say a plane), the verticle axis is most likely always 0 (or rather -9.81), probably invalidating all assumptions done in that method. But I am not too familiar with the code / logic involved to say for sure. All I know is that I stumbled over a youtube video that instead of nudging along the normal tried to handle slopes by following the surface tangent and correcting for the loss of remaining translation by re-normalizing to the previous magnitude.

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.

3 participants