public void UpdateATL(ThirdPersonUserControl player_three, Crosshair crosshair, CurvySpline spline) { _targetDelay -= Time.deltaTime; // aim through crosshair Quaternion targetDirection = Quaternion.LookRotation(crosshair.transform.forward); // passed the crosshair and delay if (_targetDelay < 0.5f) { if (_speed > 10.0f) { _speed -= Time.deltaTime; } if (Vector3.Distance(gameObject.transform.position, player_three.transform.position) < 5.0f) { onceAround = true; } // going around track if (!onceAround) { float t = spline.GetNearestPointTF(gameObject.transform.position); t *= .95f; Vector3 splineUp = spline.GetRotatedUpFast(t, 0); Vector3 targetPosition = spline.Interpolate(t) + splineUp * 1.7f; targetDirection = Quaternion.LookRotation((targetPosition - transform.position).normalized); } // circling player - should be the gun else if (onceAround) { targetDirection = Quaternion.LookRotation(((player_three.transform.position + player_three.transform.up) - transform.position).normalized); //aim at heart } } transform.rotation = Quaternion.Slerp(transform.rotation, targetDirection, Time.deltaTime); Vector3 velocity = (transform.forward) * _speed; GetComponent <Rigidbody>().MovePosition(transform.position + velocity * Time.deltaTime); }
public void UpdateATL(ThirdPersonUserControl player, CurvySpline spline) { if (!init && spline.IsInitialized) { init = true; } if (!init) { return; } //print("mouse x " + Input.GetAxis("Mouse X") + ", mouse y " + Input.GetAxis("Mouse Y")); offset += new Vector3(-Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"), 0.0f); t = spline.GetNearestPointTF(player.transform.position); Vector3 splineUp = spline.GetRotatedUpFast(t, 0); //AxKDebugLines.AddLine (player.transform.position, player.transform.position + splineUp, Color.red, .001f); Vector3 splineForward = spline.GetTangent(t); Vector3 splineRight = Vector3.Cross(splineUp, splineForward); Vector3 tempOffset = splineRight * offset.x + splineUp * offset.y; //changed from Vector3.up float targetPositionT = t - offsetCrosshair / spline.Length; Vector3 targetT = spline.Interpolate(targetPositionT); Vector3 targetPosition = targetT + tempOffset; transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * smooth * 3.0f); //transform.localRotation = Quaternion.Slerp( transform.localRotation, Quaternion.LookRotation (-splineForward.normalized), Time.deltaTime * smooth ); //clamp the final position to this Vector3 pos = Camera.main.WorldToViewportPoint(transform.position); pos.x = Mathf.Clamp01(pos.x); pos.y = Mathf.Clamp01(pos.y); transform.position = Camera.main.ViewportToWorldPoint(pos); //transform.position = targetPosition; transform.localRotation = Camera.main.transform.localRotation; if (fire) //fire is only true for one frame { _small.gameObject.GetComponent <Renderer> ().material = fireS; _medium.gameObject.GetComponent <Renderer> ().material = fireM; _large.gameObject.GetComponent <Renderer> ().material = fireL; //print ("in fire, mat name = " + _medium.gameObject.GetComponent<Renderer> ().material.name); StartCoroutine(Delay(.5f)); } else if (aim && !fire) { _small.localRotation = Quaternion.Euler(transform.localRotation.y, transform.localRotation.x, tempOffset.x * 300.0f); _medium.localRotation = Quaternion.Euler(transform.localRotation.y, transform.localRotation.x, tempOffset.y * 300.0f); //y = Time.time; // * 180.0f; // Quaternion.AngleAxis (Time.time * 180.0f , transform.forward); _small.gameObject.GetComponent <Renderer> ().material = aimS; _medium.gameObject.GetComponent <Renderer> ().material = aimM; _large.gameObject.GetComponent <Renderer> ().material = aimL; //print ("in aim, mat name = " + _medium.gameObject.GetComponent<Renderer> ().material.name); } else { //ease back. only call on return _small.localRotation = Quaternion.Slerp(_small.localRotation, Quaternion.Euler(Vector3.zero), Time.deltaTime); _medium.localRotation = Quaternion.Slerp(_medium.localRotation, Quaternion.Euler(Vector3.zero), Time.deltaTime); _small.gameObject.GetComponent <Renderer> ().material = readyS; _medium.gameObject.GetComponent <Renderer> ().material = readyM; _large.gameObject.GetComponent <Renderer> ().material = readyL; //print ("in ready, mat name = " + _medium.gameObject.GetComponent<Renderer> ().material.name); } }
public void UpdateATL(ThirdPersonUserControl player, CurvySpline spline) { if (!init && spline.IsInitialized) { init = true; } if (!init) { return; } if (!Camera.main.GetComponent <CameraController_three> ().CUbool&& !wasdDone) { //player.GetComponentInChildren<MakeMesh> (true).enabled = true; MakeTextGO("TO MOVE HOLD DOWN WASD"); //0-17 before "W" wasdDone = true; } if (Input.GetKeyDown(KeyCode.W) && !wPressed) { SwapCharGO(' ', 14); // replace W with a space wPressed = true; } if (Input.GetKeyDown(KeyCode.A) && !aPressed) { SwapCharGO(' ', 15); aPressed = true; } if (Input.GetKeyDown(KeyCode.S) && !sPressed) { SwapCharGO(' ', 16); sPressed = true; } if (Input.GetKeyDown(KeyCode.D) && !dPressed) { SwapCharGO(' ', 17); dPressed = true; } // conditionals for which words to show if (wPressed && sPressed && aPressed && dPressed && !wasdCleared) { Clear(); wasdCleared = true; } if (player.GetComponent <ThirdPersonCharacter> ().SeenGun() && !qDone && wasdCleared) //must evade intro wide with gun in view { MakeTextGO("PRESS Q TO PICKUP"); qDone = true; } if (player.GetComponent <ThirdPersonCharacter> ().m_pickup == true && !mouseAimDone) { MakeTextGO("PRESS LEFT MOUSE DOWN TO AIM"); mouseAimDone = true; } if (player.GetComponent <ThirdPersonCharacter> ().m_doneAim == true && !mouseFireDone) { MakeTextGO("RELEASE LEFT MOUSE TO FIRE"); mouseFireDone = true; //StartCoroutine (Fade (4.0f)); //do on fireFlag below } if (player.GetComponent <ThirdPersonCharacter> ().m_fireFlag == true & !fireCleared) { Clear(); fireCleared = true; } float t = spline.GetNearestPointTF(player.transform.position); //AxKDebugLines.AddSphere (spline.Interpolate (maxT), 0.3f, Color.green); //AxKDebugLines.AddSphere (spline.Interpolate (minT), 0.3f, Color.magenta); Vector3 splineUp = spline.GetRotatedUpFast(t, 0); Vector3 splineForward = spline.GetTangent(t); Vector3 splineRight = Vector3.Cross(splineUp, splineForward); //Vector3 rise = splineRight * offset.x + splineUp * offset.y + splineForward * offset.z; Vector3 lookPosition = Camera.main.transform.position; //Vector3 targetPosition = player.transform.position + player.transform.right * 0.8f * textLength / 4 + player.transform.up * 4.0f - player.transform.forward * 3.0f; Vector3 targetPosition = spline.Interpolate(t) + splineRight * 0.8f * textLength / 3 + splineUp * 4.0f - splineForward * 3.0f; //AxKDebugLines.AddSphere (lookPosition, .1f, Color.red); //AxKDebugLines.AddSphere (targetPosition, .1f, Color.blue); transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * smooth); transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation((lookPosition - transform.position).normalized), Time.deltaTime * smooth); }
public void UpdateATL(ThirdPersonUserControl player, CurvySpline spline) { if (!init && spline.IsInitialized) { init = true; t = spline.GetNearestPointTF(player.transform.position); minT = t - (buffer / spline.Length) / 2.0f; maxT = t + (buffer / spline.Length) / 2.0f; } if (!init) { return; } //print ("spline name = " + spline.name); float playerT = spline.GetNearestPointTF(player.transform.position); //print ("playerT = " + playerT); //AxKDebugLines.AddSphere (player.transform.position, 0.3f, Color.green); //AxKDebugLines.AddSphere (spline.Interpolate (player.transform.position), 0.3f, Color.magenta); //AxKDebugLines.AddSphere (spline.Interpolate (playerT), 0.3f, Color.blue); if (playerT > maxT) { maxT = playerT; minT = maxT - (buffer / spline.Length); t = playerT; } else if (playerT < minT) { minT = playerT; maxT = minT + (buffer / spline.Length); t = playerT; } //AxKDebugLines.AddSphere (spline.Interpolate (maxT), 0.3f, Color.green); //AxKDebugLines.AddSphere (spline.Interpolate (minT), 0.3f, Color.magenta); splineUp = spline.GetRotatedUpFast(t, 0); splineForward = spline.GetTangent(t); splineRight = Vector3.Cross(splineUp, splineForward); //print ("offset = " + offset); Vector3 rise = splineUp * offset.y + splineForward * offset.z + splineRight * offset.x * Mathf.Sin(Mathf.Sqrt(Time.time)); float targetPositionT = t + offsetCam / spline.Length; Vector3 targetPosition = spline.Interpolate(targetPositionT) + rise; float lookPositionT = t - offsetLook / spline.Length; Vector3 lookPosition = spline.Interpolate(lookPositionT); targetPosition = ((targetPosition * 4f) + player.transform.position) / 5f; if (CUbool) { lookPosition = player.transform.position + player.transform.up * 2.55f; targetPosition = lookPosition + player.transform.forward * .4f; //print ("in bool"); } else if (falling) { lookPosition = player.transform.position; targetPosition = transform.position; } transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * smooth); transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation((lookPosition - transform.position).normalized), Time.deltaTime * smooth); }