Skip to content
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

Remove hackish and not multiplayer ready crouch visuals. #2961

Merged
merged 2 commits into from
Dec 21, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,10 @@
import org.terasology.logic.characters.GazeMountPointComponent;
import org.terasology.logic.characters.MovementMode;
import org.terasology.logic.characters.events.OnItemUseEvent;
import org.terasology.logic.characters.events.SetMovementModeEvent;
import org.terasology.logic.characters.interactions.InteractionUtil;
import org.terasology.logic.debug.MovementDebugCommands;
import org.terasology.logic.delay.DelayManager;
import org.terasology.logic.location.LocationComponent;
import org.terasology.logic.notifications.NotificationMessageEvent;
import org.terasology.logic.players.event.OnPlayerSpawnedEvent;
import org.terasology.math.AABB;
import org.terasology.math.Direction;
Expand All @@ -68,9 +66,7 @@
import org.terasology.math.geom.Vector3f;
import org.terasology.network.ClientComponent;
import org.terasology.network.NetworkSystem;
import org.terasology.physics.engine.CharacterCollider;
import org.terasology.physics.engine.PhysicsEngine;
import org.terasology.physics.engine.SweepCallback;
import org.terasology.registry.In;
import org.terasology.rendering.AABBRenderer;
import org.terasology.rendering.BlockOverlayRenderer;
Expand All @@ -84,8 +80,6 @@

import java.util.List;

import static org.terasology.logic.characters.KinematicCharacterMover.VERTICAL_PENETRATION_LEEWAY;

// TODO: This needs a really good cleanup
// TODO: Move more input stuff to a specific input system?
// TODO: Camera should become an entity/component, so it can follow the player naturally
Expand Down Expand Up @@ -119,13 +113,13 @@ public class LocalPlayerSystem extends BaseComponentSystem implements UpdateSubs
private boolean isAutoMove = false;
private boolean runPerDefault = true;
private boolean run = runPerDefault;
private boolean crouchPerDefault = false;
private boolean crouch = false;
private boolean jump;
private float lookPitch;
private float lookPitchDelta;
private float lookYaw;
private float lookYawDelta;
private float crouchFraction = 0.5f;

@In
private Time time;
Expand Down Expand Up @@ -193,46 +187,6 @@ private void processInput(EntityRef entity, CharacterMovementComponent character
jump = false;
}

/**
* Reduces height and eyeHeight by crouchFraction and changes MovementMode.
*/
private void crouchPlayer(EntityRef entity) {
crouch = true;
ClientComponent clientComp = entity.getComponent(ClientComponent.class);
GazeMountPointComponent gazeMountPointComponent = clientComp.character.getComponent(GazeMountPointComponent.class);
float height = clientComp.character.getComponent(CharacterMovementComponent.class).height;
float eyeHeight = gazeMountPointComponent.translate.getY();
movementDebugCommands.playerHeight(localPlayer.getClientEntity(), height * crouchFraction);
movementDebugCommands.playerEyeHeight(localPlayer.getClientEntity(), eyeHeight * crouchFraction);
clientComp.character.send(new SetMovementModeEvent(MovementMode.CROUCHING));
}

/**
* Checks if there is an impenetrable block above,
* Raises a Notification "Cannot stand up here!" if present
* If not present, increases height and eyeHeight by crouchFraction and changes MovementMode.
*/
private void standPlayer(EntityRef entity) {
crouch = false;
ClientComponent clientComp = entity.getComponent(ClientComponent.class);
GazeMountPointComponent gazeMountPointComponent = clientComp.character.getComponent(GazeMountPointComponent.class);
float height = clientComp.character.getComponent(CharacterMovementComponent.class).height;
float eyeHeight = gazeMountPointComponent.translate.getY();
Vector3f pos = entity.getComponent(LocationComponent.class).getWorldPosition();
// Check for collision when rising
CharacterCollider collider = physics.getCharacterCollider(clientComp.character);
// height used below = (1 - crouch_fraction) * standing_height
Vector3f to = new Vector3f(pos.x, pos.y + (1 - crouchFraction) * height / crouchFraction, pos.z);
SweepCallback callback = collider.sweep(pos, to, VERTICAL_PENETRATION_LEEWAY, -1f);
if (callback.hasHit()) {
entity.send(new NotificationMessageEvent("Cannot stand up here!", entity));
return;
}
movementDebugCommands.playerHeight(localPlayer.getClientEntity(), height / crouchFraction);
movementDebugCommands.playerEyeHeight(localPlayer.getClientEntity(), eyeHeight / crouchFraction);
clientComp.character.send(new SetMovementModeEvent(MovementMode.WALKING));
}

// To check if a valid key has been assigned, either primary or secondary and return it
private Input getValidKey(List<Input> inputs) {
for(Input input: inputs) {
Expand Down Expand Up @@ -378,26 +332,16 @@ public void onToggleSpeedTemporarily(ToggleSpeedTemporarilyButton event, EntityR
// Crouches if button is pressed. Stands if button is released.
@ReceiveEvent(components = {ClientComponent.class}, priority = EventPriority.PRIORITY_NORMAL)
public void onCrouchTemporarily(CrouchButton event, EntityRef entity) {
ClientComponent clientComp = entity.getComponent(ClientComponent.class);
CharacterMovementComponent move = clientComp.character.getComponent(CharacterMovementComponent.class);
if (event.isDown() && move.mode == MovementMode.WALKING) {
crouchPlayer(entity);
} else if (!event.isDown() && move.mode == MovementMode.CROUCHING) {
standPlayer(entity);
}
boolean toggle = event.isDown();
crouch = crouchPerDefault ^ toggle;
event.consume();
}

@ReceiveEvent(components = {ClientComponent.class}, priority = EventPriority.PRIORITY_NORMAL)
public void onCrouchMode(CrouchModeButton event, EntityRef entity) {
ClientComponent clientComp = entity.getComponent(ClientComponent.class);
CharacterMovementComponent move = clientComp.character.getComponent(CharacterMovementComponent.class);
if (event.isDown()) {
if (move.mode == MovementMode.WALKING) {
crouchPlayer(entity);
} else if (move.mode == MovementMode.CROUCHING) {
standPlayer(entity);
}
crouchPerDefault = !crouchPerDefault;
crouch = !crouch;
}
event.consume();
}
Expand Down