-
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
Changes from 5 commits
5212bad
f94718f
26f8f98
1e21cc6
6b915ef
87596cf
851d6b6
fa8d3ed
944bc1e
9de2a0b
f29f784
0b002b9
cb8015c
3acd387
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,13 @@ | |
import org.terasology.entitySystem.entity.EntityManager; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.terasology.logic.characters.CharacterImpulseEvent; | ||
import org.terasology.logic.common.DisplayNameComponent; | ||
import org.terasology.logic.characters.CharacterComponent; | ||
import org.terasology.logic.characters.GazeMountPointComponent; | ||
import org.terasology.logic.characters.CharacterMovementComponent; | ||
import org.terasology.logic.characters.CharacterTeleportEvent; | ||
import org.terasology.logic.characters.GazeMountPointComponent; | ||
import org.terasology.logic.characters.CharacterImpulseEvent; | ||
import org.terasology.logic.characters.MovementMode; | ||
import org.terasology.logic.common.DisplayNameComponent; | ||
import org.terasology.logic.location.Location; | ||
import org.terasology.logic.location.LocationComponent; | ||
import org.terasology.math.geom.Quat4f; | ||
|
@@ -46,6 +47,8 @@ | |
|
||
import java.util.Optional; | ||
|
||
import static java.lang.Math.pow; | ||
|
||
@RegisterSystem | ||
@Share(MovementDebugCommands.class) | ||
public class MovementDebugCommands extends BaseComponentSystem { | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. The default This is how the jump speed is adjusted according to this function, for |
||
} | ||
|
||
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 commentThe 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: |
||
} | ||
|
||
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 commentThe 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 |
||
} | ||
|
||
@Command(shortDescription = "Sets the height of the player", runOnServer = true, | ||
requiredPermission = PermissionManager.CHEAT_PERMISSION) | ||
public String playerHeight(@Sender EntityRef client, @CommandParam("height") float amount) { | ||
skaldarnar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
try { | ||
ClientComponent clientComp = client.getComponent(ClientComponent.class); | ||
CharacterMovementComponent move = clientComp.character.getComponent(CharacterMovementComponent.class); | ||
if (move != null) { | ||
CharacterComponent charComp = clientComp.character.getComponent(CharacterComponent.class); | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. I believe The best shot could be to define constants in |
||
|
||
if (move != null && gazeMountPointComponent != null) { | ||
float prevHeight = move.height; | ||
|
||
move.height = amount; | ||
gazeMountPointComponent.translate.y = amount; | ||
move.jumpSpeed = getJumpSpeed(amount); | ||
move.stepHeight = 0.35f * ratio; | ||
move.distanceBetweenFootsteps = ratio; | ||
move.runFactor = getRunFactor(amount); | ||
charComp.interactionRange = getInteractionRange(amount); | ||
|
||
Location.removeChild(player, gazeMountPointComponent.gazeEntity); | ||
Location.attachChild(player, gazeMountPointComponent.gazeEntity, gazeMountPointComponent.translate, new Quat4f(Quat4f.IDENTITY)); | ||
player.saveComponent(gazeMountPointComponent); | ||
clientComp.character.saveComponent(move); | ||
LocationComponent loc = client.getComponent(LocationComponent.class); | ||
Vector3f currentPosition = loc.getWorldPosition(); | ||
clientComp.character | ||
.send(new CharacterTeleportEvent(new Vector3f(currentPosition.getX(), currentPosition.getY() + (amount - prevHeight) / 2, currentPosition.getZ()))); | ||
physics.removeCharacterCollider(clientComp.character); | ||
physics.getCharacterCollider(clientComp.character); | ||
|
||
return "Height of player set to " + amount + " (was " + prevHeight + ")"; | ||
} | ||
return ""; | ||
|
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
ispublic
inCharacterMovementComponent
, so there should be no need for this getter method.See CharacterMovementComponent.java#L39