-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat: improve 'playerHeight' command #3841
Conversation
Can one of the admins please verify this patch? |
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.
Initial style concerns.
I'll do a proper review soon
engine/src/main/java/org/terasology/logic/debug/MovementDebugCommands.java
Outdated
Show resolved
Hide resolved
engine/src/main/java/org/terasology/logic/debug/MovementDebugCommands.java
Outdated
Show resolved
Hide resolved
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.
@godfather2 thanks for this PR.
Would be nice if you could come back to this once the proposal deadline is over.
There are some style guide violations in this PR. Resolving them should also help with making the code more readable and self-documenting (better names).
Potions should use a AffectHeightComponent instead of affecting the PlayerConfig settings. These should override the Default (config) values and should be serialized to the world save.
Is that item really outstanding before merging or could it be done as a follow-up?
engine/src/main/java/org/terasology/logic/debug/MovementDebugCommands.java
Outdated
Show resolved
Hide resolved
@@ -233,22 +231,44 @@ public String stepHeight(@Sender EntityRef client, @CommandParam("height") float | |||
return ""; | |||
} | |||
|
|||
private float function1(float parameter){ | |||
double p = (double)parameter; | |||
return (float) pow(p,0.6) * 0.78f ; |
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.
What's the reason to cast between float and doubles here? Wouldn't the following work?
private double calculateSomething(double p) {
return pow(p, 0.6) * 0.78;
}
I guess this could even be inlined.
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 values returned from the functions are assigned to float variables.Hence the cast
return (float) pow(p,0.6) * 0.78f ; | ||
} | ||
|
||
private float function2(float parameter){ |
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.
Same here, please use a better name for the method.
engine/src/main/java/org/terasology/logic/debug/MovementDebugCommands.java
Outdated
Show resolved
Hide resolved
GazeMountPointComponent gazeMountPointComponent = player.getComponent(GazeMountPointComponent.class); | ||
|
||
float ratio = amount / 1.6f; | ||
float constant= function1(amount); |
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.
What constant is calculated based off the height (amount)? Is it the eye level or something like that?
move.jumpSpeed = 12 * constant; | ||
move.stepHeight = 0.35f * ratio; | ||
move.distanceBetweenFootsteps = ratio; | ||
move.runFactor = function2(amount); |
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.
If function2
computes the run factor (whatever that is) you could call it getRunFactor
instead.
…ommands.java Co-Authored-By: Tobias Nett <[email protected]>
@skaldarnar "Potions should use a AffectHeightComponent instead of affecting the PlayerConfig settings. These should override the Default (config) values and should be serialized to the world save." |
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 changes are much more comprehensible now with better naems for the functions and variables.
One question, though: where did you get the formulas from? They don't match the default values, unfortunately, which I think would be a requirement to meet. Should also be possible to write tests for.
@@ -91,6 +91,8 @@ public Vector3f getVelocity() { | |||
return velocity; | |||
} | |||
|
|||
public float getPlayerHeight(){ return height; } |
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 member height
is public
in CharacterMovementComponent
, so there should be no need for this getter method.
EntityRef player = clientComp.character; | ||
GazeMountPointComponent gazeMountPointComponent = player.getComponent(GazeMountPointComponent.class); | ||
|
||
float ratio = amount / 1.6f; |
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 believe 1.6f
is the default height of the player? Ideally, we don't have to copy around these magic numbers and loose track of where they came from.
The best shot could be to define constants in CharacterMovementComponent
which can be reused here.
engine/src/main/java/org/terasology/logic/debug/MovementDebugCommands.java
Show resolved
Hide resolved
@@ -233,22 +236,48 @@ public String stepHeight(@Sender EntityRef client, @CommandParam("height") float | |||
return ""; | |||
} | |||
|
|||
private float getJumpSpeed(float amount){ | |||
double d = (double)amount; | |||
return (float) pow(d,0.6) * 9.36f ; |
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 default jumpSpeed
seems to be 10 (and that's the maximum at the same time o.O ). thus, I would assume that setting the player height to the default should result in the default jump speed, but substituting amount
by 1.6 yiels a value ~12.4 (≠10).
This is how the jump speed is adjusted according to this function, for amount
in the interval from 0 to 5:
see Wolfram Alpha
} | ||
|
||
private float getRunFactor(float amount){ | ||
return 0.15f + (0.64f * amount) - (0.006f * amount * amount); |
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 run factor seems to be a value in the range from 0 to 10, with 1.5 being the default.
Again, calculating the new run factor with the default height of 1.6 yields a value of 1.15864 (≠1.5).
This is how the run factor scales with the given function for amount
between 0 and 5. The curve looks almost linear, to be hones:
see Wolfram Alpha
|
||
private float getInteractionRange(float amount){ | ||
double d = (double)amount; | ||
return (float) pow(d,0.6) * 3.9f ; |
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 default interaction range seems to be 5 (see CharacterComponent.java#L37). With this formula the interaction range for height of 1.6 is 5.17055 (≠ 5).
This is what the plot looks like:
see Wolfram Alpha
This pull request introduces 1 alert when merging fa8d3ed into 0579738 - view on LGTM.com new alerts:
|
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.
Note that in all the suggested formulas I've use height/DEFAULT_HEIGHT
(which is exactly the ratio
you've computed before). This is in order to get that term to equal 1 for the default height, and thus result in the default value.
All the functions should get the ratio as an argument, and not the height.
float defaultHeight = move.height; | ||
float defaultStepHeight = move.stepHeight; | ||
float defaultFootSteps = move.distanceBetweenFootsteps; |
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.
This does not take the default values, but the current values for the CharacterMovementComponent.
private float getJumpSpeed(float amount){ | ||
double d = (double)amount; | ||
return Math.round(pow(d,0.55) * 8.45f); | ||
} |
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.
private float getJumpSpeed(float amount){ | |
double d = (double)amount; | |
return Math.round(pow(d,0.55) * 8.45f); | |
} | |
private float getJumpSpeed(float height) { | |
return Math.round(Math.pow(height/DEFAULT_HEIGHT, 0.55f) * DEFAULT_JUMP_SPEED); | |
} |
private float getInteractionRange(float amount){ | ||
double d = (double)amount; | ||
return Math.round(pow(d,0.6) * 3.9f); | ||
} |
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.
private float getInteractionRange(float amount){ | |
double d = (double)amount; | |
return Math.round(pow(d,0.6) * 3.9f); | |
} | |
private float getInteractionRange(float height){ | |
return Math.round(pow(height/DEFAULT_HEIGHT, 0.6) * DEFAULT_INTERACTION_RANGE); | |
} |
private float getRunFactor(float amount){ | ||
return Math.round(5.5f + (6.4f * amount) - (0.06f * amount * amount)) / 10f; | ||
} |
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.
Maybe use a similar formular to the ones you use above? Is there any reason this should be quadratic?
private float getRunFactor(float amount){ | |
return Math.round(5.5f + (6.4f * amount) - (0.06f * amount * amount)) / 10f; | |
} | |
private float getRunFactor(float height){ | |
return Math.round(Math.pow(height/DEFAULT_HEIGHT, 0.5) * DEFAULT_RUN_FACTOR);; | |
} |
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.
well....its just that i painstakingly constructing the other 2 functions manually,before i realized that it is much easier to arrive at them through regression,and that is how i acquired the third function.I must admit @skaldarnar you are really thorough
EntityRef player = clientComp.character; | ||
GazeMountPointComponent gazeMountPointComponent = player.getComponent(GazeMountPointComponent.class); | ||
|
||
float defaultHeight = 1.6f; |
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.
These should not be re-defined here. When the default values in CharacterMovementComponent are changed these will be outdated, and will likely cause some weird behavior and bugs.
Instead, CharacterMovementComponent
should expose
public static final float DEFAULT_HEIGHT = 1.6f;
public static final float DEFAULT_JUMP_SPEED = 10.f;
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 just looked at the restoreSpeed
command. This is how it accesses default values CharacterMovementComponent moveDefault = prefab.get().getComponent(CharacterMovementComponent.class);
for instance move.jumpSpeed = moveDefault.jumpSpeed;
Should i do this?
engine/src/main/java/org/terasology/logic/characters/CharacterMovementComponent.java
Outdated
Show resolved
Hide resolved
engine/src/main/java/org/terasology/logic/debug/MovementDebugCommands.java
Outdated
Show resolved
Hide resolved
engine/src/main/java/org/terasology/logic/debug/MovementDebugCommands.java
Outdated
Show resolved
Hide resolved
engine/src/main/java/org/terasology/logic/debug/MovementDebugCommands.java
Outdated
Show resolved
Hide resolved
engine/src/main/java/org/terasology/logic/debug/MovementDebugCommands.java
Outdated
Show resolved
Hide resolved
Optional<Prefab> prefab = Assets.get(new ResourceUrn("engine:player"), Prefab.class); | ||
CharacterMovementComponent moveDefault = prefab.get().getComponent(CharacterMovementComponent.class); | ||
|
||
if (move != null && gazeMountPointComponent != null) { |
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.
Ideally we'll need a lot more null checks here (for all the components). I'll refactor that part after this PR is merged, though.
engine/src/main/java/org/terasology/logic/debug/MovementDebugCommands.java
Outdated
Show resolved
Hide resolved
gazeMountPointComponent.translate.y = amount - foreHeadSize; | ||
Location.removeChild(player, gazeMountPointComponent.gazeEntity); | ||
Location.attachChild(player, gazeMountPointComponent.gazeEntity, gazeMountPointComponent.translate, new Quat4f(Quat4f.IDENTITY)); | ||
|
||
player.saveComponent(gazeMountPointComponent); |
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.
As this is the same code as for the playerEyeHeight
command I would refactor this later on to use a common
updateGazeMountPointHeight(player, amount - foreHeadSize);
return "Height of player set to " + amount + " (was " + prevHeight + ")"; | ||
} | ||
return ""; | ||
} catch (NullPointerException e) { |
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.
If we did proper null checks this try-catch block should not be necessary (in general, catching a NPE is always a code smell as you could have done a null-check before).
engine/src/main/java/org/terasology/logic/debug/MovementDebugCommands.java
Outdated
Show resolved
Hide resolved
I think that this command should, under the hood, use a Merging this now as clear improvement and good progress to get the logic right. |
Contains
Attempt to fix #2535 .
The character's jump speed,movement speed,interaction range and step height are a function of the player's height.I acquired the functions through play testing and graph plotters.
Earlier, a change in the player's height was made through a change in the his position through teleportation.This is probably what caused the player to sink through blocks at dwarf heights.This pull request, on the other hand just changes the eye height of the player.
"Increase/Decrease damage from fall. (30m giant should not die of a 15m fall). Define function/proportionality constant same as above."->this sub issue is dealt by a pull request in the health module
How to test
Just change the player's height and his capabilities should increase or decrease accordingly.
Outstanding before merging