-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 physics overrides for walk speed and Fast Mode #13815
Conversation
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.
movement_speed_fast * physics_override.speed_fast
exists way too many times. Perhaps you could make it a local variable in LocalPlayer::applyControl
?
EDIT: That's not related to this PR, but I wonder if movement_speed_walk
should get its own speed_walk
override. Modifying movement_speed_walk
via the speed
override has the disadvantage that it also affects all other speed and acceleration overrides.
With this PR, every player physics value (movement_ settings) will be overridable by Lua. The Fast Mode settings are the two missing ones.
So this isn't exactly true, movement_speed_walk
is missing too.
Thanks for pointing out the mistakes, seems like I overlooked some things. This should be fixed now. About The most important thing to me that any change must be 100% backwards-compatible with the previous stable version. So for now I would rather err on the side of caution but maybe a nice solution can be found. In any case, this discussion should be resolved BEFORE the next release. |
Adding a Something like this should work: diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp
index 0dd70a884..658d8d2ae 100644
--- a/src/client/localplayer.cpp
+++ b/src/client/localplayer.cpp
@@ -536,6 +536,7 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
// Whether superspeed mode is used or not
bool superspeed = false;
+ f32 speed_walk = movement_speed_walk * physics_override.speed_walk;
f32 speed_fast = movement_speed_fast * physics_override.speed_fast;
if (always_fly_fast && free_move && fast_move)
@@ -554,9 +555,9 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
if (fast_move)
speedV.Y = -speed_fast;
else
- speedV.Y = -movement_speed_walk;
+ speedV.Y = -speed_walk;
} else if ((in_liquid || in_liquid_stable) && !m_disable_descend) {
- speedV.Y = -movement_speed_walk;
+ speedV.Y = -speed_walk;
swimming_vertical = true;
} else if (is_climbing && !m_disable_descend) {
speedV.Y = -movement_speed_climb * physics_override.speed_climb;
@@ -586,12 +587,12 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
if (fast_move && (control.aux1 || always_fly_fast))
speedV.Y = -speed_fast;
else
- speedV.Y = -movement_speed_walk;
+ speedV.Y = -speed_walk;
} else if ((in_liquid || in_liquid_stable) && !m_disable_descend) {
if (fast_climb)
speedV.Y = -speed_fast;
else
- speedV.Y = -movement_speed_walk;
+ speedV.Y = -speed_walk;
swimming_vertical = true;
} else if (is_climbing && !m_disable_descend) {
if (fast_climb)
@@ -619,12 +620,12 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
if (fast_move)
speedV.Y = speed_fast;
else
- speedV.Y = movement_speed_walk;
+ speedV.Y = speed_walk;
} else {
if (fast_move && control.aux1)
speedV.Y = speed_fast;
else
- speedV.Y = movement_speed_walk;
+ speedV.Y = speed_walk;
}
}
} else if (m_can_jump) {
@@ -643,7 +644,7 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
if (fast_climb)
speedV.Y = speed_fast;
else
- speedV.Y = movement_speed_walk;
+ speedV.Y = speed_walk;
swimming_vertical = true;
} else if (is_climbing && !m_disable_jump && !control.sneak) {
if (fast_climb)
@@ -660,7 +661,7 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
else if (control.sneak && !free_move && !in_liquid && !in_liquid_stable)
speedH = speedH.normalize() * movement_speed_crouch * physics_override.speed_crouch;
else
- speedH = speedH.normalize() * movement_speed_walk;
+ speedH = speedH.normalize() * speed_walk;
speedH *= control.movement_speed; /* Apply analog input */
(I wanted to put this into a
I don't see any backwards compatibility problems here. |
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.
Looks good to me now, but I suggest also adding speed_walk
in this PR. (This is not a requirement.)
Okay, you convinced me. I am now willing to add support for |
Walking speed added. I also added some remarks to the documentation and updated the 1st post. |
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.
Walking speed added. I also added some remarks to the documentation and updated the 1st post.
I also spotted and fixed a minor bug in the anticheat that underestimated the max. legal speed.
Thank you.
Oh no, it looks like we just entered feature freeze so this change is apparently not going to make it into 5.8. :-( |
I think that renaming the fields like |
Hey @Wuzzy2, how's it going with this PR? |
I didn't forget about this, but there was this game jam. XD I think I may pick this up again later. |
27a8816
to
675abf3
Compare
I've resolved the latest @grorp comments and also did a rebase since the code has diverged again.
Not having fallbacks is asking for trouble. |
That's not what I meant. What I meant is that you're resetting too many fields here in some cases. If you connect a 5.9.0-dev client (with this PR) to a 5.8.0 server that sends a |
Sorry. The reason why I stopped updating this is because I didn't know what I was supposed to do. *shrug* |
Alright, just fixed it myself. *shrug*
Fixed by grorp@661e3dc Adopted in #14475. |
Follow-up PR for #11465 based on a suggestion by @grorp.
This PR adds the following new fields to
set_physics_override
:speed_walk
: Normal walking speedspeed_fast
: Speed in Fast Modeacceleration_fast
: Acceleration in Fast Modespeed_fast
andacceleration_fast
modify themovement_speed_fast
andmovement_acceleration_fast
settings by simple multiplication. Like most physics modifiers, they default to 1.speed_walk
will multiplymovement_speed_walk
and only affects the walking speed, i.e. not crouching, climbing or Fast Mode.The player physics are not changed, this PR merely exposes some player physics values to be modifiable by Lua.
Additionally, the Client mod documentation is updated for the new physics overrides (including those added by #11465).
Also, I fixed a small bug in the anticheat because it underestimated the possible max. speed.
With this PR, every player physics value (
movement_
settings) will be overridable by Lua. The walk speed and Fast Mode settings are the missing ones.How to test
Please test this extensively before merging!
I recommend you to use
luacmd
andorienteering
mods. Get yourself a speedometer with/giveme orienteering:speedometer
and put it in the hotbar. This displays your speed at the top which is very useful for testing.Now, in DevTest, call
me:set_physics_override(table_of_physics_you_want_to_test)
. Test the normal walk speed and Fast Mode. Also test sneaking and climbing if you want to, just to make sure those still work as expected.Then check if it does what you expect to / what the documentation promises.
Note that the player physics must be completely unchanged if you have not called this function so far. It is also very important this PR is 100% backwards-compatible.
I made some basic tests playing around with various physics overrides. But I did not test networking.
Notes about speed
Note that
speed
and the otherspeed_*
settings are multiplied with each other.speed
is supposed to affect all player speed, no matter the movement type. This is required to keep backwards-compability. All the otherspeed_*
values likespeed_fast
will only affect the corresponding movement type.Example 1:
speed=2, speed_fast=6
must result in 6× speed in fast mode but only 2× speed for all other movement types.Example 2:
speed=0
must stop all player movement.Example 3:
speed_walk=0
must only stop walking speed but Fast Mode, sneaking and climbing must be unaffected.