public async void PickUp(Furniture fur, bool instant = false) { if (fur != null) { if (this.carryingFurniture == null) { PlayRandomGrabSound(); if (fur.playersCarrying.Count != 0) { instant = true; } this.animator.SetBool("carrying", true); if (instant == false) { this.playerState = CustomEnums.PlayerState.sleep; await Task.Delay(TimeSpan.FromSeconds(GameParams.Main.carrySleepTimeInSeconds)); } if (fur == null) { playerState = CustomEnums.PlayerState.normal; return; } fur.OnPickedUp(this, instant); lastNearestFurniture = null; nearestFurniture = null; } } }
private void Move() { joystickStrength = new Vector2(Input.Horizontal, Input.Vertical).magnitude; Mathf.Clamp(joystickStrength, 0, 1); if (cam != null) { camForward = Vector3.Scale(cam.transform.forward, new Vector3(1, 0, 1)).normalized; direction = Input.Vertical * camForward + Input.Horizontal * cam.transform.right; } direction.Normalize(); if (playerState == CustomEnums.PlayerState.carryingWithOthers) { playerTransform.LookAt(new Vector3(this.carryingPointTransform.transform.position.x, this.playerTransform.position.y, this.carryingPointTransform.transform.position.z), Vector3.up); if (joystickStrength > .25f) { vel = rb.velocity; vel.x = direction.x * Time.fixedDeltaTime * (WalkSpeed) * 100 * joystickStrength; vel.y = 0; vel.z = direction.z * Time.fixedDeltaTime * (WalkSpeed) * 100 * joystickStrength; rb.velocity = vel; } else { if (this.carryingFurniture != null) { carryingFurniture.pivotPoint = this.playerTransform.position; rb.velocity = Vector3.zero; } else { playerState = CustomEnums.PlayerState.normal; } } } else { if (joystickStrength > .25f) { playerTransform.rotation = Quaternion.Slerp(playerTransform.rotation, Quaternion.LookRotation(direction), RotationSpeed); vel = rb.velocity; vel.x = direction.x * Time.fixedDeltaTime * (WalkSpeed) * 100 * joystickStrength; vel.y = 0; vel.z = direction.z * Time.fixedDeltaTime * (WalkSpeed) * 100 * joystickStrength; rb.velocity = vel; } else { rb.velocity = Vector3.zero; } } }
public void Drop() { if (this.carryingFurniture != null && this.playerState != CustomEnums.PlayerState.sleep) { this.animator.SetBool("carrying", false); this.carryingFurniture.OnDropped(this); this.carryingFurniture = null; this.playerState = CustomEnums.PlayerState.normal; this.ResetCarryingPoint(); } }
private async void Dash() { //SET UP CustomEnums.PlayerState previousState = this.playerState; this.playerState = CustomEnums.PlayerState.dashing; if (this.carryingFurniture != null && carryingFurniture.playersCarrying.Count > 1) { for (int i = this.carryingFurniture.playersCarrying.Count - 1; i >= 0; i--) { if (this.carryingFurniture.playersCarrying[i] != this) { this.carryingFurniture.playersCarrying[i].Drop(); } } } this.animator.SetBool("dash", true); if (dashTrail != null) { this.dashTrail.emitting = true; } Instantiate(GameParams.Main.dashParticuleEffect, this.playerTransform.position, this.playerTransform.rotation); float actualMalus = this.speedMalus; float t = 0; float slow = 1; if (this.carryingFurniture != null) { slow = this.carryingFurniture.weight.Remap(GameParams.Main.weights[0], GameParams.Main.weights[GameParams.Main.weights.Length - 1], .5f, 2.5f); } //ACTUALLY MOVING while (t <= (GameParams.Main.dashTime)) { this.rb.AddForce(transform.forward.normalized * ((GameParams.Main.dashDistance / (slow * GameParams.Main.dashSlowAccentuation)) / GameParams.Main.dashTime), ForceMode.Acceleration); t += Time.fixedDeltaTime; await Task.Delay(1); } //DASH END if (this.playerState == CustomEnums.PlayerState.dashing) { this.playerState = previousState; } this.animator.SetBool("dash", false); if (dashTrail != null) { this.dashTrail.emitting = false; } if (this.carryingFurniture == null) { this.speedMalus = 5; await Task.Delay(TimeSpan.FromSeconds(GameParams.Main.dashSlowDuration)); this.speedMalus = 0; } }
private void Update() { if (this.playerState != CustomEnums.PlayerState.sleep && (GameManager.Main.gameState == CustomEnums.GameState.Menu || (GameManager.Main.gameState == CustomEnums.GameState.InSession && GameManager.Main.currentSession.sessionState == CustomEnums.SessionState.NormalGame) || (GameManager.Main.gameState == CustomEnums.GameState.InSession && GameManager.Main.currentSession.sessionState == CustomEnums.SessionState.Overtime) )) { if (playerState == CustomEnums.PlayerState.normal && Time.frameCount % 5 == 0) { nearestFurniture = GetNearestFurniture(false); } if (Input.InteractIsPressed && Time.time > nextInteract) { nextInteract = Time.time + .2f; OnInteractionPressed(); } if (Input.DashIsPressed && Time.time > nextDash) { nextDash = Time.time + GameParams.Main.playerDashCooldown; Dash(); } } //STATS if ((GameManager.Main.gameState == CustomEnums.GameState.InSession && GameManager.Main.currentSession.sessionState == CustomEnums.SessionState.NormalGame) || (GameManager.Main.gameState == CustomEnums.GameState.InSession && GameManager.Main.currentSession.sessionState == CustomEnums.SessionState.Overtime) ) { stats.distanceTravelled += Vector3.Distance(playerTransform.position, lastPos); if (this.carryingFurniture != null && (this.carryingFurniture.data.furnitureWeight == CustomEnums.WeightEnum.heavy || this.carryingFurniture.data.furnitureWeight == CustomEnums.WeightEnum.superHeavy)) { stats.distanceTravelledWithHeavyObjects += Vector3.Distance(playerTransform.position, lastPos); } if (this.carryingFurniture != null && (this.carryingFurniture.playersCarrying.Count > 1)) { stats.distanceTravelledTogether += Vector3.Distance(playerTransform.position, lastPos); } //ANTI BUG CHECK if (Vector3.Distance(playerTransform.position, lastPos) == 0) { timeWithoutMoving += Time.deltaTime; if (timeWithoutMoving > 3) { if (carryingFurniture == null) { playerState = CustomEnums.PlayerState.normal; } else if (carryingFurniture.playersCarrying.Count == 1) { playerState = CustomEnums.PlayerState.carrying; } else { playerState = CustomEnums.PlayerState.carryingWithOthers; } timeWithoutMoving = 0; } } } if (walkDustDistance > 3) { DustParticules(); walkDustDistance = 0; } walkDustDistance += Vector3.Distance(playerTransform.position, lastPos); lastPos = this.playerTransform.position; }