public void MoveX(float value) { if (isTransposed) { shadowMoveScript.MoveInput(value); shadowAnimator.SetFloat("Speed", Mathf.Abs(value)); } else { bodyMoveScript.MoveInput(value); bodyAnimator.SetFloat("Speed", Mathf.Abs(value)); shadowAnimator.SetFloat("Speed", Mathf.Abs(value)); } }
private void Update() { Vector3 bodyToShadow = shadow.transform.position - body.transform.position; bodyToShadow.z = 0f; float bodyToShadowMagnitude = bodyToShadow.magnitude; float bodyToShadowMagnitudeDivByMaxDistance = bodyToShadowMagnitude / maxShadowDistance; if (bodyToShadowMagnitudeDivByMaxDistance > 1.05f) { //If the shadow his to far, reset it ResetShadow(); } else if (!isTransposed) { shadow.transform.rotation = body.transform.rotation; shadowMoveScript.DirectMove(body.transform.position + shadowOffset - shadow.transform.position); shadowOffset = shadow.transform.position - body.transform.position; } else { if (bodyToShadowMagnitudeDivByMaxDistance > 0.5f) { MaxRangeCircleSprite.color = new Color(1f, 1f, 1f, (bodyToShadowMagnitudeDivByMaxDistance > 1f ? 1f : (bodyToShadowMagnitudeDivByMaxDistance - 0.5f) * 2f)); } else { MaxRangeCircleSprite.color = new Color(1f, 1f, 1f, 0f); } if (bodyToShadowMagnitude > maxShadowDistance) { //Found the exedente of distance between the max distance and the actual distance and multiply it by the current vector to get the exedent vector. bodyToShadow *= (bodyToShadowMagnitudeDivByMaxDistance) - 1f; //Reset the exedent position from the body to the shadow shadowMoveScript.DirectMove(-bodyToShadow); shadowMoveScript.moveDirection = Vector3.zero; } // Remove the player velocity on x to prevent the player from moving/sliding (if on ground) // If the player is not on ground, it should have disableInputs = false; bodyMoveScript.MoveInput(0f); } }