idanarye / bevy-tnua

A floating character controller for Bevy
https://crates.io/crates/bevy-tnua
Apache License 2.0
214 stars 14 forks source link

Add a parameter that controls the max slope the character can walk up #42

Closed ethereumdegen closed 4 months ago

ethereumdegen commented 7 months ago

I dont see any paramter for this and my character can walk up EXTREMLY steep inclines -- not good

idanarye commented 7 months ago

I'm wondering how this should connect to #10 and #11.

janhohenheim commented 7 months ago

Imo, if we had to pick between this and #10 as a feature, I think we should pick the max slope. While a slippery ground is a bit of a gimmick, next to every 3D game has varying slopes, so forcing them all to use perfectly "straight" walls everywhere the player shouldn't be able to go through is a bit of a bummer

idanarye commented 7 months ago

The reason I want to connect this to #10 is that setting a max slope is slipping. If the player jumps on a steep slope, we want to make them slip down. If I separate between the slope detection and the slipping down, the same two features can be used:

Steep Slope Slippery Surface
Surface Detection Check normal Check surface components
Slipping Set to full slipperiness (can't climb up) Set partial slipperiness (can move slower, with less acceleration)
ethereumdegen commented 7 months ago

I agree w this — for open game worlds like mine its very useful to be able to say 50 degree slopes are impassable” as a hard set limit instead of relying on wonky physics only because its very important to be able to control player agency and esp without making invisible walls yes exactly

I see commonly this is achieved by casting multiple rays / sensors or i suppose reading the normal of the collision in front idk

On Thu, Feb 22, 2024 at 1:35 PM Jan Hohenheim @.***> wrote:

Imo, if we had to pick between this and #10 https://github.com/idanarye/bevy-tnua/issues/10 as a feature, I think we should pick the max slope. While a slippery ground is a bit of a gimmick, next to every 3D game has varying slopes, so forcing them all to use perfectly "straight" walls everywhere the player shouldn't be able to go through is a bit of a bummer

— Reply to this email directly, view it on GitHub https://github.com/idanarye/bevy-tnua/issues/42#issuecomment-1960034491, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABPVWL4K6QSUFYAZDTPPXJTYU6FY3AVCNFSM6AAAAABDQJXUOOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRQGAZTINBZGE . You are receiving this because you authored the thread.Message ID: @.***>

idanarye commented 7 months ago

Okay, Okay...

Here is the plan: I'll add a new max_slope parameter to TnuaBuiltinWalk, which will default to half PI (right angle). If the angle between the proximity sensor's normal and the up direction is higher than that, the basis will go into "lost grip" mode, which would mean:

  1. The character will be considered airborne:
    • So that it can't just keep jumping. Unless it has air actions, of course - but then it'll be wasting them.
    • We also want the animating systems to play the in-air animations when this happens. Of course, this state would be queryable so one could have a special animation for that, if they want to.
  2. Instead of applying the spring force in the up direction, it'll be applied in the direction of the normal. Since gravity still apply, this will mean the character will be pushed down-slope.
  3. The basis will cap the part of the forces it would apply in the upslope direction:
    • Without that the player could use air mobility to force the character up the slope.
    • Actually, even if the player wouldn't try to force the character up the slope, the basis would still try to apply forces to "brake" the slide - and we want to prevent that.

One problem I can think of with this plan is that if the game allows unlimited air dashes, these air dashes could be used to force the character up the slope. Not sure how urgent it is to address it though.

janhohenheim commented 7 months ago

Aah @idanarye, I see now. Didn't think of impassible slopes as slipping before, but you're totally right!

idanarye commented 4 months ago

Took me quite a while (mainly because this is PITA code and I had other stuff to work on), but it seems to be working quite nicely:

https://github.com/idanarye/bevy-tnua/assets/1149255/98869b1a-798f-4992-8153-ce4e79b784c0

As you can see in the video, it doesn't work very well for low slopes. But I'm not sure this usecase is important enough to make it worth fixing. At least not right now.

janhohenheim commented 4 months ago

Thanks for implementing it ❤️