Beispiel #1
0
 private void OnCollisionEnter(Collision collision)
 {
     //Crash
     runner.follow = false;
     //Cursor.lockState = CursorLockMode.None;
     EndScreen.Open();
 }
Beispiel #2
0
 public void SetSpeed(float speed)
 {
     this.speed         = speed;
     runner.followSpeed = speed;
     if (speed == 0f)
     {
         EndScreen.Open();
     }
 }
Beispiel #3
0
 private void OnCollisionStay(Collision collision)
 {
     if (Vector3.Dot(trs.up, Vector3.up) < 0.5f)
     {
         deathTime -= Time.deltaTime;
         if (deathTime <= 0f)
         {
             EndScreen.Open();
         }
     }
 }
 void Die()
 {
     if (dead)
     {
         return;
     }
     dead        = true;
     rb.velocity = Vector2.zero;
     rb.AddForce((Vector2.up + Vector2.left * 0.2f) * initialJumpForce * 2f, ForceMode2D.Impulse);
     rb.constraints = RigidbodyConstraints2D.None;
     rb.AddTorque(45f);
     GetComponent <CapsuleCollider2D>().enabled = false;
     EndScreen.Open();
 }
Beispiel #5
0
        void FixedUpdate()
        {
            for (int i = 0; i < engines.Length; i++)
            {
                Ray        ray = new Ray(engines[i].position, -engines[i].up);
                RaycastHit hit;
                float      forceRatio = 0f;
                //Raycast from each engine and apply hover force
                if (Physics.Raycast(ray, out hit, hoverHeight))
                {
                    Matrix4x4 hitMatrix          = Matrix4x4.TRS(hit.point, Quaternion.LookRotation(projector.result.forward, hit.normal), Vector3.one);
                    Vector3   engineVelocity     = rb.GetPointVelocity(engines[i].position);
                    Vector3   localHoverVelocity = hitMatrix.inverse.MultiplyVector(engineVelocity);

                    forceRatio = hoverCurve.Evaluate((hoverHeight - hit.distance) / hoverHeight);
                    Vector3 appliedHoverForce = engines[i].up * forceRatio * hoverForce;
                    if (localHoverVelocity.y < Mathf.Clamp(rb.velocity.magnitude * 0.15f, 0.5f, 2f))
                    {
                        rb.AddForceAtPosition(appliedHoverForce, engines[i].position, ForceMode.Force);
                    }
                    if (localHoverVelocity.y > 0f && forceRatio < 0.6f)
                    {
                        rb.AddForceAtPosition(-engines[i].up * localHoverVelocity.y * Mathf.InverseLerp(0.6f, 0f, forceRatio) * stabilizerStrenght, engines[i].position, ForceMode.Force);
                    }
                }
            }
            //Create a matrix from the current projected result
            Matrix4x4 resultMatrix = Matrix4x4.TRS(projector.result.position, Quaternion.LookRotation(projector.result.forward, Vector3.up), Vector3.one);
            //Set the rotation of the player to match the path direction
            //but also retain the local roll and pitch
            Vector3 resultLocalPlayerForward = resultMatrix.inverse.MultiplyVector(trs.forward);

            resultLocalPlayerForward.x = 0f;
            resultLocalPlayerForward.Normalize();
            rb.MoveRotation(Quaternion.LookRotation(resultMatrix.MultiplyVector(resultLocalPlayerForward), trs.up));

            //Handle player physics forces
            Vector3 localTorque = trs.InverseTransformDirection(rb.angularVelocity);

            localTorque.y      = 0f;
            rb.angularVelocity = trs.TransformDirection(localTorque);
            Vector3 localVelocity = trs.InverseTransformDirection(rb.velocity);

            if (forwardInput > 0f && localVelocity.z < maxSpeed)
            {
                rb.AddForce(projector.result.forward * acceleration * forwardInput * accelerationCurve.Evaluate(localVelocity.z / maxSpeed), ForceMode.Force);
            }
            else if (forwardInput < 0f && localVelocity.z > 0f)
            {
                rb.AddForce(-projector.result.forward * brakeForce * -forwardInput, ForceMode.Force);
            }
            if ((sidewaysInput > 0f && localVelocity.x < turnSpeed) || (sidewaysInput < 0f && localVelocity.x > -turnSpeed))
            {
                rb.AddRelativeForce(Vector3.right * sidewaysInput * agility, ForceMode.Force);
            }
            rb.AddForce(Vector3.down * gravityForce, ForceMode.Acceleration);
            localVelocity   = resultMatrix.inverse.MultiplyVector(rb.velocity);
            localVelocity.z = Mathf.Clamp(localVelocity.z, -maxSpeed, maxSpeed);
            localVelocity.x = Mathf.Clamp(localVelocity.x, -turnSpeed, turnSpeed);
            rb.velocity     = resultMatrix.MultiplyVector(localVelocity);

            if (transform.position.y <= -30)
            {
                EndScreen.Open();
            }

            if (transform.rotation.z >= 150 || transform.rotation.z <= -150)
            {
                EndScreen.Open();
            }
        }
Beispiel #6
0
 private void Awake()
 {
     instance = this;
 }