// Update is called once per frame private void FixedUpdate() { if (isSliding) { CalculateSlidingSpeed(); //Bottom block check if (Physics.Raycast(transform.position, bottomBlockDir, out bottomBlockRay, 1f)) { previousBottomBlockRay = bottomBlockRay; if (bottomBlockRay.collider.GetComponent <IValidStandingSpace>().IsValidToStandOn()) { if (bottomBlockRay.collider.tag != "Sliding Block") { ToggleSlide(false, -1); transform.position = bottomBlockRay.collider.transform.position + new Vector3(0, 1f, 0); } } } else { ToggleSlide(false, -1); transform.position = previousBottomBlockRay.collider.transform.position + slidingDir; fallingMechanic.ToggleFall(true); } if (Physics.Raycast(transform.position, slidingDir, out forwardBlockRay, 1f)) { if (forwardBlockRay.collider.gameObject != null) { if (forwardBlockRay.collider.GetComponent <IValidStandingSpace>().IsValidToStandOn()) { if (forwardBlockRay.collider.tag != "Sliding Block") { ToggleSlide(false, -1); transform.position = forwardBlockRay.collider.transform.position - slidingDir; } } } } } }
void Update() { if (audioSource == null && GameObject.Find("Player Sounds") != null) { audioSource = GameObject.Find("Player Sounds").GetComponent <MasterAudioSystem>(); } if (isPrepToDie) { KillTheBox(); isPrepToDie = false; } if (isPrepForFalling && !isMoving) { fallingMechanic.ToggleFall(true); isPrepForFalling = false; } if (isPrepForSliding) { slidingMechanic.ToggleSlide(true, previousDirection); isPrepForSliding = false; } if (isMoving) { if (Vector3.Distance(transform.position, newPos) > 0.0001f) { float fracComplete = (Time.time - startTime) / journeyTime * speed; transform.position = Vector3.Lerp(transform.position, newPos, fracComplete * speed); } else { isMoving = false; } } }
// Update is called once per frame void Update() { surrBlockCond = new bool?[5]; float moveX = 0.0f, moveZ = 0.0f; if (!finishSpawnAnim && !characterAnimation.GetCurrentAnimatorStateInfo(0).IsName("Player Spawn")) { finishSpawnAnim = true; characterAnimation.applyRootMotion = true; } if (stillJumping && !characterAnimation.GetCurrentAnimatorStateInfo(0).IsName("Player Hop")) { stillJumping = false; characterModel.transform.localPosition = new Vector3(0, 0, 0); } if (!isMoving && !isDead) { if (!fallingMechanic.IsDoneFalling()) { goLeft = false; goRight = false; goDown = false; goUp = false; } if (!fallingMechanic.IsPlayerFalling() && !slideMechanic.IsSliding() && !isSailing && !isMoving && finishSpawnAnim) { if (currIdleTime <= idleAnimStartTime) { currIdleTime += Time.deltaTime; } else { if (characterAnimation.GetCurrentAnimatorStateInfo(0).IsName("Player")) { characterAnimation.SetTrigger("Idle"); } } if (goLeft) { goLeft = false; characterModel.eulerAngles = new Vector3(0, relForwardAngle, 0); surrBlockCond = CheckPlayerSurrondings(relLeft); previousRelDir = relLeft; previousDir = 1; moveX = relLeftVec.x; moveZ = relLeftVec.y; startMoving = true; StopIdling(); } if (goRight) { goRight = false; characterModel.eulerAngles = new Vector3(0, relForwardAngle + 180f, 0); surrBlockCond = CheckPlayerSurrondings(relRight); previousRelDir = relRight; previousDir = 2; moveX = relRightVec.x; moveZ = relRightVec.y; startMoving = true; StopIdling(); print("going right"); } if (goDown) { goDown = false; characterModel.eulerAngles = new Vector3(0, relForwardAngle + 270f, 0); surrBlockCond = CheckPlayerSurrondings(relBackward); previousRelDir = relBackward; previousDir = 3; moveX = relBackwardVec.x; moveZ = relBackwardVec.y; startMoving = true; StopIdling(); } if (goUp) { goUp = false; characterModel.eulerAngles = new Vector3(0, relForwardAngle + 90f, 0); surrBlockCond = CheckPlayerSurrondings(relForward); previousRelDir = relForward; previousDir = 4; moveX = relForwardVec.x; moveZ = relForwardVec.y; startMoving = true; StopIdling(); } } if (startMoving) { characterAnimation.applyRootMotion = true; newPos = Vector3.zero; Vector3 translationAmount = Vector3.zero; if (CheckValidMovemement(surrBlockCond) == 0) { translationAmount = new Vector3(moveX, 1f, moveZ); ToggleGrabbingState(false); } else if (CheckValidMovemement(surrBlockCond) == 1) { translationAmount = new Vector3(moveX, 0f, moveZ); } else if (CheckValidMovemement(surrBlockCond) == -1) { translationAmount = Vector3.zero; } else { translationAmount = new Vector3(moveX, 0f, moveZ); isPrepForFalling = true; ToggleGrabbingState(false); } newPos = transform.position + translationAmount; GetArchCenter(Vector3.up * 0.1f, transform.position, newPos); startTime = Time.time; isMoving = true; startMoving = false; characterAnimation.SetTrigger("Hop"); audioSource.PlayPlayerSound("Hop"); stillJumping = true; if (isGrabbing) { GetComponent <DragObject>().MoveBlock(previousRelDir); } } } else { if (Vector3.Distance(transform.position, newPos) > 0.0001f) { float fracComplete = (Time.time - startTime) / journeyTime * speed; transform.position = Vector3.Slerp(startRelCenter, endRelCenter, fracComplete * speed); transform.position += centerPoint; if (isPrepForFalling && characterAnimation.GetCurrentAnimatorStateInfo(0).normalizedTime >= (cutOffFallAnimTime)) { PauseHoppingAnimation(); } } else { isMoving = false; if (isPrepToSlide) { slideMechanic.ToggleSlide(true, previousDir); isPrepToSlide = false; } if (isPrepForFalling) { fallingMechanic.ToggleFall(true); isPrepForFalling = false; } if (isPrepareToDie) { KillThePlayer(); isPrepareToDie = false; } } } }