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
Simple client-side autojump. Remove hardcoded Android stepheight #7228
Conversation
At the time of writing, the "collision detection" part is basically broken. I was trying to use the collision results from the movement code, but those seem to be incomplete / unusable for this purpose? Sometimes I don't even get the collision from the ground I'm standing on 🙁 Still, the jumping part works, if you want to test it, it just may need running against a wall a bit. At the moment, the wall can be more than one block high; testing this is planned, but futile until I find a good detection method in the first place. I may have to simulate a jump and see if the player "fits better". Other suggestions welcome! |
Interesting and appreciated. I'm just wondering if there needs to be some server control over allowing this clientside option, probably yes as no having to use the jump button is inevitably a control advantage. |
You can't really control this server-side, but it's less of an advantage than you think. Currently it's triggering by actually colliding with something (and hence stopping). If you manually jump before you reach the wall, you get to keep your horizontal speed. There will also certainly be situations in which autojump triggers even if you would rather not jump; again not a problem with manual control. So I would not agree to it being "inevitably a control advantage". And even if it is: if it's available to everyone, can you call it an advantage? Or are you thinking of singleplayer / PvE games that want to make / keep the game more challenging for players? In that case I could see a use for a server turning it off, but I would caution against coding up yet another option until servers ask for it… |
Yes i'm unsure if server control is needed or worth doing, for now i'm not asking for it, server owners can advise on this.
Well what i mean is most players will not want to use it, and they shouldn't feel any pressure to use it due to any slight advantages it gives to other players. So that argument is invalid in my opinion. |
a3bbc22
to
7b7db8b
Compare
@paramat Ah, I see what you mean with "pressure to use it", thanks. A new version is up. It appears that The jump key is now "held down" for a while, and sneaking disables autojump. |
I really like this! It feels much more natural than using an increased stepheight (like on Android), and if made default on Android would remove the perceived speed advantage the increased stepheight gives Android users. There is one possible issue I spotted (though I am aware this is still WIP); when going up stairs there is an occasional higher "hop" in addition to the regular half-jump of normal stair ascent. I've made a quick video of this PR here: https://www.youtube.com/watch?v=DGVdEnrXk1E&feature=youtu.be |
7b7db8b
to
55980a7
Compare
@Wayward1 thanks for checking this out! Yes, it's still quite rough – it still needs some work on heights and collisions. I'll be sure to study your video! In related news, autojump now has it's own setting (default off), including a checkbox in the key controls gui. |
55980a7
to
642eb9c
Compare
I've got a new implementation: whenever the player collides horizontally, I test the same colliding movement one node higher. If it turns out that this results in a bit more horizontal movement, I trigger an autojump. This seems to work very well; single-node obstacles are reliably cleared, more than that is not even attempted. This works equally well with slabs and stairs; regular up-stepping movement no longer triggers a jump. I had to add a field to the collision info struct for this, to help me find "horizontal collisions". I hope that's ok. Since I imagine collision detection is quite costly, I want to limit it to such cases. All that's left to do is to refactor the autojump into a method and add this to |
src/localplayer.cpp
Outdated
if (autojump_time <= 0.0f) { | ||
autojump = false; | ||
} | ||
} else if (m_can_jump && !control.jump && !control.sneak && control.up && g_settings->getBool("autojump")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The autojump setting should be cached instead of reading it from settings frequently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point; do you have an example of a cached setting that I could copy? Just off the top of your head?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll look. We can cache this because it is not a setting that will change in-game.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it will; it's part of the key change GUI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be solved with the PlayerSettings
construct.
Seems ok, collisions are costly so this seems good. |
642eb9c
to
dd9a828
Compare
Autojumping is now in it's own method and works in the old movement code as well (and should work with joysticks, though I'll have to test this later). Since I've gotten all that I want from this PR, I'm removing the "WIP". There is still the issue with settings caching above, don't worry, I haven't forgotten! Just need to wrap my head around settings callback handlers 😛 The player will actually bang their head, repeatedly, when running against a node that is clear above, but that has a ceiling in front of it. There is a method for this in |
Please see #7243 for a proposed solution to settings caching. That PR does not contain Would this help with the settings reading concerns? |
dd9a828
to
850d9ee
Compare
I have rebased this PR again, incorporating #7243 changes, and have added I haven't tried building and testing on Android, yet, has someone had a look? Specifically, I'm not sure how good the behaviour can be enabled and disabled in the client. |
I just tested this on Android, and it works great! And it's as easy as any other advanced setting to change as well |
Provocative question, can PC users have this configurable feature too? Disabled by default |
@Fixer-007 this is available for all users. |
850d9ee
to
22d934d
Compare
79ed26d
to
5c7d871
Compare
There was still a linting problem outstanding; I must have missed this. Fixed (and rebased while we're at it). |
This is high in my priority queue, i'll review and hopefully add the 2nd approval soonish. |
@paramat Just wondering - how long is your priority queue? EDIT: Can we please finally get this PR into the game? |
LOL sorry. This should certainly be in for 5.0.0. |
Apart from my line comment code looks good. |
src/localplayer.cpp
Outdated
// jumped | ||
v3f run_delta = position_before_move - m_position; | ||
run_delta.Y = 0.0f; | ||
v3f jump_delta = position_before_move - jump_pos; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and above. Mathematically works but the order of terms bothers me because a movement vector is 'final pos' - 'start pos'.
Works by detecting a collision while moving forward and then simulating a jump. If the simulated jump is more successful, an artificial jump key press is injected in the client. Includes setting and key change GUI element for enabling and disabling this feature.
5c7d871
to
a6ecc80
Compare
src/localplayer.cpp
Outdated
run_delta.Y = 0.0f; | ||
v3f jump_delta = position_before_move - jump_pos; | ||
v3f jump_delta = initial_position - jump_pos; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might as well swap the terms too, i'm +1 and you can merge this if you do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a 1D example:
Moving from 2 to 5 is a movement of +3, which is '5 - 2', 'final - initial'.
These deltas are wrong (inverted), they only work because getting the length of a vector is unaffected by the sign.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whether it's correct or wrong depends on the viewpoint. Deltas can be measured in all directions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somewhat true, but a delta is usually measured going forwards in time from initial to final position.
src/localplayer.cpp
Outdated
@@ -1147,9 +1147,9 @@ void LocalPlayer::handleAutojump(f32 dtime, Environment *env, | |||
|
|||
// see if we can get a little bit farther horizontally if we had | |||
// jumped | |||
v3f run_delta = position_before_move - m_position; | |||
v3f run_delta = initial_position - m_position; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swap terms.
Tested and working nicely on android 👍 |
Hi there, sorry I took so long before reacting. Thanks @SmallJoker for stepping in – I take it it's been rebased now, too? @paramat I got an email that you have a question about "always jumping", but I can't find it above any more. I'd have to review the code again, but I'm pretty sure the "simulate the jump key" feature only works if you're moving into something while on the ground, so it's "released" as soon as you're airborne at least. But I'll have another look. Edit: I've checked, the key is "held" for 100ms, then released again and could be re-pressed. |
@bendeutsch Yes, I rebased the PR on the fly because I wanted to make sure that it works on the current HEAD as well (it does). |
I deleted the comment soon after because i realised i was wrong, there's no problem. |
…st#7228) Works by detecting a collision while moving forward and then simulating a jump. If the simulated jump is more successful, an artificial jump key press is injected in the client. Includes setting and key change GUI element for enabling and disabling this feature.
…st#7228) Works by detecting a collision while moving forward and then simulating a jump. If the simulated jump is more successful, an artificial jump key press is injected in the client. Includes setting and key change GUI element for enabling and disabling this feature.
…st#7228) Works by detecting a collision while moving forward and then simulating a jump. If the simulated jump is more successful, an artificial jump key press is injected in the client. Includes setting and key change GUI element for enabling and disabling this feature.
During the movement phase, the client detects when an automatic jump is in order (based on collisions and such). Then, during the (next) control collection phase, a "jump" control is simulated.
The autojump is transparent for the server. It is indistinguishable from a regular jump, in fact it is a regular jump, just not triggered by the player but by the client software. The actual motion code is also unchanged.
Currently, jumps are only triggered when the player is moving forwards and is standing on solid ground and not swimming. The feature will be toggleable by a client setting (default enabled on mobile devices, disabled otherwise).
////////////
EDIT by paramat: For #6183