Vector2 getInput(float horizontal, float vertical) { //calculating direction vector Vector3 direction = new Vector3(horizontal, 0.0f, vertical); //create rotated transform that is locked to avoid up/down camera angle affecting direction magnitude Quaternion cameraRotation = cam.transform.rotation; cam.transform.Rotate(Vector3.left, cam.transform.localRotation.eulerAngles.x); direction = cam.transform.TransformDirection(direction); direction.y = 0.0f; //revert camera's rotation cam.transform.rotation = cameraRotation; //limit input magnitude (to avoid high-magnitude input when moving diagonally) direction = Vector3.Normalize(direction); //ease direction for smoother movement (dampen direction change if in air) float changer = directionChangeSpeed; if (jumping) { changer *= airDampening; } targetDirection.x = Nox.ease(targetDirection.x, direction.x, changer); targetDirection.y = Nox.ease(targetDirection.y, direction.z, changer); //amplify normalized vector to desired speed return(new Vector2(targetDirection.x, targetDirection.y) * targetSpeed); }
void Update() { if (Nox.player.GetComponent <PlayerMove>().flying&& Input.GetMouseButton(0)) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, Mathf.Infinity, mask)) { targetPoint = hit.point; } soundSystem.addEnergy(1f); } if (Mathf.Abs(targetPoint.x - flyPoint.transform.position.x) > 1f && Mathf.Abs(targetPoint.z - flyPoint.transform.position.z) > 1f) { float newX = Nox.ease(flyPoint.transform.position.x, targetPoint.x, 1f); float newY = Nox.ease(flyPoint.transform.position.y, targetPoint.y, 1f); float newZ = Nox.ease(flyPoint.transform.position.z, targetPoint.z, 1f); flyPoint.transform.position = new Vector3(newX, newY, newZ); } //audio if (Nox.player.GetComponent <PlayerMove>().flying&& Input.GetMouseButtonDown(0)) { soundSystem.dynamicToggle("pads", true); } if (Nox.player.GetComponent <PlayerMove>().flying&& Input.GetMouseButtonUp(0)) { soundSystem.dynamicToggle("pads", false); } }
void handleInput() { //get input float mouseX = Input.GetAxis("Mouse X"); float mouseY = -Input.GetAxis("Mouse Y"); if (!ready) { mouseX = 0; mouseY = 0; } //rotation manipulation rotY += mouseX * mouseSensitivity * Time.deltaTime; rotX += mouseY * mouseSensitivity * Time.deltaTime; rotX = Mathf.Clamp(rotX, -clampAngle, clampAngle); //ease rotation currentX = Nox.ease(currentX, rotX, easeSpeed); currentY = Nox.ease(currentY, rotY, easeSpeed); //apply rotation Quaternion localRotation = Quaternion.Euler(currentX, currentY, 0.0f); transform.rotation = localRotation; }
void Update() { if (Input.GetMouseButtonDown(1)) { if (letterBox != null) { StopCoroutine(letterBox); } letterBox = StartCoroutine(changeAspectRatio(aspectRatio)); } if (Input.GetMouseButtonUp(1)) { if (letterBox != null) { StopCoroutine(letterBox); } letterBox = StartCoroutine(changeAspectRatio(cam.aspect)); } //override when flying if (Nox.player.GetComponent <PlayerMove>().flying) { if (letterBox != null) { StopCoroutine(letterBox); } if (currentAspect != cam.aspect) { currentAspect = Nox.ease(currentAspect, cam.aspect, aspecRatioChangeSpeed / 4f); } forceAspectRatio(currentAspect); } }
void follow() { float x = Nox.ease(transform.position.x, player.transform.position.x, followSpeed); float y = Nox.ease(transform.position.y, player.transform.position.y + 0.5f, followSpeed); float z = Nox.ease(transform.position.z, player.transform.position.z, followSpeed); transform.position = new Vector3(x, y, z); }
void setFOV() { if (GameObject.Find("Camera").GetComponent <SunClick>().transitioning == null) { if (!flying) { targetFOV = Nox.ease(targetFOV, Nox.remap(targetSpeed, walkSpeed, sprintSpeed, defaultFOV, fastFOV), FOVease); } camComponent.fieldOfView = targetFOV; } }
void follow() { Vector3 targetPosition = Camera.main.transform.position + (Camera.main.transform.forward * targetDistance); Vector3 newPosition = transform.position; newPosition.x = Nox.ease(newPosition.x, targetPosition.x, followSpeed); newPosition.y = Nox.ease(newPosition.y, targetPosition.y, followSpeed); newPosition.z = Nox.ease(newPosition.z, targetPosition.z, followSpeed); transform.position = newPosition; transform.rotation = Camera.main.transform.rotation; }
void FixedUpdate() { Vector3 targetPosition = Camera.main.transform.position + (Camera.main.transform.forward * distanceFromCamera); Vector3 newPosition = transform.position; newPosition.x = Nox.ease(newPosition.x, targetPosition.x, followSpeed); newPosition.y = Nox.ease(newPosition.y, targetPosition.y, followSpeed); newPosition.z = Nox.ease(newPosition.z, targetPosition.z, followSpeed); velocity = Vector3.Distance(transform.position, newPosition); rb.MovePosition(newPosition); }
IEnumerator FadeSky(float target) { while (Mathf.Abs(skyOpacity - target) > 0.02f) { yield return(new WaitForSeconds(0.01f)); skyOpacity = Nox.ease(skyOpacity, target, 0.05f); sky.multiplier.value = skyOpacity; } skyOpacity = target; sky.multiplier.value = skyOpacity; }
IEnumerator FadeBackground(float target) { while (Mathf.Abs(backgroundOpacity - target) > 0.02f) { yield return(new WaitForSeconds(0.01f)); backgroundOpacity = Nox.ease(backgroundOpacity, target, 0.1f); storyBackground.GetComponent <CanvasGroup>().alpha = backgroundOpacity; } backgroundOpacity = target; storyBackground.GetComponent <CanvasGroup>().alpha = backgroundOpacity; }
IEnumerator Fade(float target) { yield return(new WaitForSeconds(fadeDelay)); while (Mathf.Abs(opacity - target) > 0.01f) { yield return(new WaitForSeconds(0.01f)); opacity = Nox.ease(opacity, target, fadeSpeed); } opacity = target; }
IEnumerator Glow() { float alpha = maxAlpha; light.SetFloat("_Alpha", alpha); while (alpha > minAlpha) { yield return(new WaitForSeconds(0.01f)); alpha = Nox.ease(alpha, minAlpha, 2f); light.SetFloat("_Alpha", alpha); } }
IEnumerator SwitchWorlds() { negative = !negative; float cut; mix.GetFloat("LP_Freq", out cut); FOV = camComponent.fieldOfView; while (FOV > 10f) { yield return(new WaitForSeconds(0.01f)); FOV = Nox.ease(FOV, 9.9f, 10f); cut = Nox.ease(cut, 3000f, 0.1f); mix.SetFloat("LP_Freq", cut); camComponent.fieldOfView = FOV; } //filter cutoff if (negative) { mix.SetFloat("LP_Freq", 1500f); } else { mix.SetFloat("LP_Freq", 22000f); } //post-processing effects if (negative) { pp.SetActive(true); } else { pp.SetActive(false); } while (FOV < 65f) { yield return(new WaitForSeconds(0.01f)); FOV = Nox.ease(FOV, 66f, 5f); camComponent.fieldOfView = FOV; } routineEnded = true; }
IEnumerator changeAspectRatio(float desiredRatio) { while (currentAspect != desiredRatio) { yield return(new WaitForSeconds(0.01f)); if (Mathf.Abs(currentAspect - desiredRatio) < 0.01f) { currentAspect = desiredRatio; } else { currentAspect = Nox.ease(currentAspect, desiredRatio, aspecRatioChangeSpeed); forceAspectRatio(currentAspect); } } }
void handleSound() { if (flying && sprinting) { soundSystem.addEnergy(2.4f); } else if (flying && !sprinting) { soundSystem.addEnergy(1.8f); } else if (sprinting) { soundSystem.addEnergy(1.4f); } else if (getSpeed() > 1f) { soundSystem.addEnergy(0.4f); } //need listener specifically for a single event //repeated calls to dynamicToggle result in loss of functionality if (Input.GetKeyDown(KeyCode.LeftShift)) { soundSystem.dynamicToggle("percussion", true); } if (Input.GetKeyUp(KeyCode.LeftShift)) { soundSystem.dynamicToggle("percussion", false); } if (jumping) { float cut; mix.GetFloat("Frequency_Cutoff", out cut); mix.SetFloat("Frequency_Cutoff", Nox.ease(cut, 1100f, 1f)); } else { float cut; mix.GetFloat("Frequency_Cutoff", out cut); mix.SetFloat("Frequency_Cutoff", Nox.ease(cut, 10f, 5f)); } }
void Update() { //modes switch (triggerLayer) { case "flight": if (Nox.player.GetComponent <PlayerMove>().flying) { if (fader != null) { StopCoroutine(fader); } if (opacity != targetOpacity) { opacity = Nox.ease(opacity, targetOpacity, (fadeSpeed / 2f) * fadeDelay); } } else { if (fader != null) { StopCoroutine(fader); } if (opacity != 0f) { opacity = Nox.ease(opacity, 0f, fadeSpeed / 2f); } } break; case "control": if (Input.GetMouseButtonDown(1)) { if (fader != null) { StopCoroutine(fader); } fader = StartCoroutine(Fade(targetOpacity)); } if (Input.GetMouseButtonUp(1)) { if (fader != null) { StopCoroutine(fader); } fader = StartCoroutine(Fade(0f)); } if (Input.GetMouseButtonDown(2)) { if (fader != null) { StopCoroutine(fader); } fader = StartCoroutine(Fade(0f)); } if (Nox.player.GetComponent <PlayerMove>().flying) { if (fader != null) { StopCoroutine(fader); } if (opacity != 0f) { opacity = Nox.ease(opacity, 0f, fadeSpeed / 2f); } } break; case "movement": if (Input.GetMouseButtonDown(2)) { if (fader != null) { StopCoroutine(fader); } fader = StartCoroutine(Fade(targetOpacity)); } if (Input.GetMouseButtonUp(2)) { if (fader != null) { StopCoroutine(fader); } fader = StartCoroutine(Fade(0f)); } if (Input.GetMouseButtonDown(1)) { if (fader != null) { StopCoroutine(fader); } fader = StartCoroutine(Fade(0f)); } if (Nox.player.GetComponent <PlayerMove>().flying) { if (fader != null) { StopCoroutine(fader); } if (opacity != 0f) { opacity = Nox.ease(opacity, 0f, fadeSpeed / 2f); } } break; } GetComponent <CanvasGroup>().alpha = opacity; }
void move() { //get input float horizontal = 0f; float vertical = 0f; if (Mathf.Abs(Input.GetAxis("Horizontal")) > 0.1f) { horizontal = Input.GetAxis("Horizontal"); } if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1f) { vertical = Input.GetAxis("Vertical"); } Vector2 direction = getInput(horizontal, vertical); Vector3 newLoc = new Vector3(gameObject.transform.position.x + direction.x, gameObject.transform.position.y, gameObject.transform.position.z + direction.y); //glue to ground, or add gravity for jump if (!flying) { if (!jumping) { newLoc = groundPlayer(newLoc); } else { rb.AddForce(new Vector3(0, -gravity, 0)); } } else { //fly rb.velocity = new Vector3(0, 0, 0); targetFOV = Nox.ease(targetFOV, flyingFOV, FOVease); if (transform.position.y < flyHeight - 0.001f) { newLoc = new Vector3(newLoc.x, Nox.ease(transform.position.y, flyHeight, flyEase), newLoc.z); } else { newLoc = new Vector3(newLoc.x, flyHeight, newLoc.z); } } //apply movement rb.MovePosition(newLoc); //jump if (Input.GetKeyDown(KeyCode.Space) && isGrounded(groundedHeight) && !jumping && !flying) { jumping = true; rb.AddForce(Vector3.up * (jumpSpeed)); StartCoroutine(jumpDelay()); } sprinting = false; //no movement - stop all forces (excluding vertical force for jumping) if (horizontal == 0f && vertical == 0f && isGrounded(groundedHeight)) { targetSpeed = Nox.ease(targetSpeed, 0f, speedChangeStop); rb.velocity = new Vector3(0, rb.velocity.y, 0); //sprint } else if (Input.GetKey(KeyCode.LeftShift)) { sprinting = true; targetSpeed = Nox.ease(targetSpeed, sprintSpeed, speedChangeSprint); //walk } else { targetSpeed = Nox.ease(targetSpeed, walkSpeed, speedChangeWalk); } }