void ArcadeFlowUpdate() { if (usedSystemType == SystemTypes.Arcade) { for (int i = 0; i < observedObjects.Count; i++) { FloatingObject obj = observedObjects[i]; if (obj.enabled == false) { continue; } slopeAngle = obj.GetNodes().closest.centerVector.y - obj.GetNodes().last.centerVector.y; Vector3 flow = obj.GetNodes().closest.finalFlowDirection; obj.GetRigidbody().AddForce(flow * ((minimumSpeed + (slopeAngle * slopeSpeedBoost)) * Time.deltaTime), ForceMode.VelocityChange); } } }
void Update() { if (skybox != null) { skybox.material.SetFloat("_Rotation", Time.time); } if (shaking) { ShakeCam(); } if (GameController.instance.GetClearGame()) { var heading1 = transform.position - (boat.transform.position + new Vector3(0, 10, 0)); var distance1 = heading1.magnitude; var direction1 = heading1 / distance1; // This is now the normalized direction. targetRotation = Quaternion.LookRotation(-direction1, Vector3.up); if (offset == Vector3.zero && slopeAngle == 0) { targetRotation.x = 0; targetRotation.z = 0; } transform.Rotate(new Vector3(-offsetAngle, 0, 0)); transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * rotationSpeed); transform.Rotate(new Vector3(offsetAngle, 0, 0)); if (beforeFade < waitBeforeFade) { beforeFade += Time.deltaTime; } else if (duringFade < waitDuringFade) { duringFade += Time.deltaTime; float alpha = duringFade / waitDuringFade; Color color = Color.white; color.a = alpha; renderer.material.color = color; } else if (afterFade < waitAfterFade) { afterFade += Time.deltaTime; } else { GameController.instance.OnCompletedLevel(); } return; } if (boat.reverseProgress) { transform.position = boat.transform.position + boatOffset + shakeOffset; //return; } Vector3 heading; float distance; Vector3 direction; // This is the normalized direction. Vector3 basePos = transform.position; Vector3 adjustPos = Vector3.zero; heading = basePos - (boat.transform.position + new Vector3(0, 5, 0)); distance = heading.magnitude; direction = heading / distance; RaycastHit hit; //Debug.DrawRay(transform.position, -heading, Color.red); blocked = false; offset = Vector3.zero; bool centerBlocked = false; if (Physics.Raycast(transform.position, -heading, out hit, distance)) { blockedHorizontal = false; if (hit.collider.gameObject.tag == "Untagged") { blocked = true; centerBlocked = true; blockedHorizontal = true; } } { adjustPos = transform.right * autoCorrectRadius; //Debug.DrawRay(transform.position - adjustPos, -heading, Color.red); //Debug.DrawRay(transform.position + adjustPos, -heading, Color.red); if (Physics.Raycast(transform.position + adjustPos, -heading, out hit, distance)) { if (hit.collider.gameObject.tag == "Untagged") { blockedHorizontal = true; blocked = true; } } if (Physics.Raycast(transform.position - adjustPos, -heading, out hit, distance)) { if (hit.collider.gameObject.tag == "Untagged") { if (blockedHorizontal == true) { blockedHorizontal = false; } else { blockedHorizontal = true; } blocked = true; adjustPos = -adjustPos; } } if (blocked) { adjustPos = -adjustPos; } } if (blocked) { offset = FixBlockedCamera(basePos, adjustPos, blockedVertical, blockedHorizontal); } RiverNode boatNode = boat.GetNodes().closest; if (boatNode != targetNode) { if (targetNode.centerVector == Vector3.zero) { targetNode = boatNode; } if (boatNode != oldTargetNode) { slopeAngle = targetNode.centerVector.y - boatNode.centerVector.y; //if (boat.transform.position.y - boatNode.centerVector.y < 0) slopeAngle = 0; heading = (targetNode.centerVector + offset + new Vector3(0, slopeAngle, 0)) - boatNode.centerVector; distance = heading.magnitude; direction = heading / distance; // This is now the normalized direction. oldTargetNode = targetNode; targetNode = boatNode; targetRotation = Quaternion.LookRotation(-direction, Vector3.up); newTarget = true; } } else { if (oldTargetNode.centerVector != Vector3.zero) { heading = (oldTargetNode.centerVector + offset + new Vector3(0, slopeAngle, 0)) - targetNode.centerVector; distance = heading.magnitude; direction = heading / distance; // This is now the normalized direction. targetRotation = Quaternion.LookRotation(-direction, Vector3.up); if (offset == Vector3.zero && slopeAngle == 0) { targetRotation.x = 0; targetRotation.z = 0; } } } transform.Rotate(new Vector3(-offsetAngle, 0, 0)); if (centerBlocked) { transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * (rotationSpeed + blockRotationSpeed)); } else if (blocked) { transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * (rotationSpeed * 2)); } else { transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * rotationSpeed); } transform.Rotate(new Vector3(offsetAngle, 0, 0)); //Gets target position targetRotationVector = transform.rotation.eulerAngles; Quaternion boatOffsetRot = Quaternion.Euler(targetRotationVector.x, targetRotationVector.y, targetRotationVector.z); boatOffset = boatOffsetRot * offsetPosition; targetPosition = boat.transform.position + boatOffset + shakeOffset; transform.position = targetPosition; }