void Update() { //Slow down the reset time a little so the raycast from the turret doesn't hit it. if (resetTime) { resetDelay++; if (resetDelay >= 5) { resetTime = false; resetDelay = 0; TimeTravelManager.Instance.ResetTime(true); } } // player presses reset time button if (PlayerManager.Instance.IsPlayer(gameObject) && controller.ResetButtonUp()) { GetComponent <MovementRecorder>().StopRecording(); transform.position = startPosition; TimeTravelManager.Instance.ResetPositions(); resetTime = true; } //If solid or dead then stop moving. if (gameObject.layer != 9 || dead) { return; } //Terminal velocity if (body.velocity.y < -terminalVelocity) { body.velocity = new Vector2(body.velocity.x, -terminalVelocity); } //Walking float horizontalV = maxHorizontalVelocity * controller.Horizontal(); if (Mathf.Abs(body.velocity.x) > Mathf.Abs(horizontalV)) //Deceleration { if (body.velocity.x > 0) { body.velocity -= new Vector2(deceleration * Time.deltaTime, 0); if (body.velocity.x < horizontalV) { body.velocity = new Vector2(horizontalV, body.velocity.y); } } else if (body.velocity.x < 0) { body.velocity += new Vector2(deceleration * Time.deltaTime, 0); if (body.velocity.x > horizontalV) { body.velocity = new Vector2(horizontalV, body.velocity.y); } } } else if (Mathf.Abs(body.velocity.x) <= Mathf.Abs(horizontalV)) //Walk { if (horizontalV > 0) { body.velocity += new Vector2(acceleration * Time.deltaTime, 0); if (body.velocity.x > horizontalV) { body.velocity = new Vector2(horizontalV, body.velocity.y); } } else if (horizontalV < 0) { body.velocity -= new Vector2(acceleration * Time.deltaTime, 0); if (body.velocity.x < horizontalV) { body.velocity = new Vector2(horizontalV, body.velocity.y); } } } //Set facing variable if (body.velocity.x > 0) { facingRight = true; } else if (body.velocity.x < 0) { facingRight = false; } //Jumping if (controller.JumpButtonDown() && jumpDelay < maxJumpDelay) { //Play SFX if (PlayerManager.Instance.IsPlayer(gameObject)) { AudioManager.Instance.Play("playerJump"); } else { AudioManager.Instance.PlayCloneSound("playerJump", transform.position); } //Set Animation anim.StartJump(); jumpDelay = maxJumpDelay; body.velocity = new Vector2(body.velocity.x, jumpVelocity); } //Height controlled by button press duration. if (controller.JumpButtonUp() && !analyser.IsGroundDown() && body.velocity.y > 0) { body.velocity = new Vector2(body.velocity.x, body.velocity.y / 2); //Can be changed from 2, it's just that 2 worked pretty nicely. } //Jumping after fall if (analyser.IsGroundDown() && body.velocity.y < 0.5f) //A little buffer so it does not need to be exactly 0 { jumpDelay = 0; } else { jumpDelay += jumpDelay < maxJumpDelay ? 1 : 0; } //Solidifying if (solidifying) { timeSinceSolidify += Time.deltaTime; float t = timeSinceSolidify / solidifyDelay; //Become solid if (t >= 1.0f) { gameObject.layer = 8; body.constraints = RigidbodyConstraints2D.FreezeAll; GetComponent <EdgeCollider2D>().enabled = false; GetComponent <BoxCollider2D>().enabled = true; anim.SetSpeed(0.0f); anim.StartSolid(); //TODO play sfx return; } body.velocity *= 1.0f - t; anim.SetSpeed(1.0f - t); anim.TurnGray(t); //Changes that only happen when player solidifies if (PlayerManager.Instance.IsPlayer(gameObject)) { AudioManager.Instance.SetThemePitch(1.0f - t); } } //Initiate Solidifying if (controller.SolidifyButtonDown()) { solidifying = true; body.gravityScale = 0; } //Clearing Checkpoint if (PlayerManager.Instance.IsPlayer(gameObject) && analyser.IsCheckpointOverlapping() && controller.ClearButtonDown()) { CheckpointManager.Instance.ClearCheckpoint(); TimeTravelManager.Instance.ResetTime(false); } //Shooting if (controller.ShootButtonDown()) { anim.StartShoot(); Vector2 forwardVector = (facingRight) ? Vector2.right : Vector2.left; Vector2 origin = (Vector2)transform.position + forwardVector * shotOffset; RaycastHit2D hit = Physics2D.Raycast(origin, forwardVector, shotDistance, LayerMask.GetMask("Character") | LayerMask.GetMask("Ground")); //Raycast forward if (hit.collider != null) { if (hit.collider.gameObject.layer == 9 && hit.collider.gameObject.tag != "Player") { hit.collider.gameObject.GetComponent <CharacterMovement>().Die(); } GameObject currentLaser = Instantiate(laser); currentLaser.GetComponent <Laser>().SetUpLaser(origin, hit.point); Destroy(currentLaser, laserDuration); } else { GameObject currentLaser = Instantiate(laser); currentLaser.GetComponent <Laser>().SetUpLaser(origin, origin + forwardVector * shotDistance); Destroy(currentLaser, laserDuration); } //Play SFX if (PlayerManager.Instance.IsPlayer(gameObject)) { AudioManager.Instance.Play("LaserShoot"); } else { AudioManager.Instance.PlayCloneSound("LaserShoot", transform.position); } } }