Ejemplo n.º 1
0
 private void AlignPlayerForwardAxisToFrameWhenMoving()
 {
     // Align forward direction towards forward gravity line
     if (rb.velocity.magnitude > alignVelocityThreshold)
     {
         Vector3    forwardDirOnFrame = gravityFrameController.FindFrameAlignedDirection(gravityFrameController.ClosestPointOnFrameLine, ForwardDir);
         Quaternion rot = Quaternion.FromToRotation(ForwardDir, forwardDirOnFrame);
         //rightDir = rot * rightDir;
         //forwardDir = rot * forwardDir;
         ForwardDir = Vector3.Slerp(ForwardDir, rot * ForwardDir, directionAlignSpeed);
         RightDir   = Vector3.Slerp(RightDir, rot * RightDir, directionAlignSpeed);
     }
 }
    /// <summary>
    /// Eats the player, by sucking into the cube and starting vignette effect.
    /// </summary>
    private void EatPlayer()
    {
        // Check whether we are the closest cube, and if so, eat!
        float distToPlayer = Vector3.Distance(CODTrans.position, playerRB.position);

        if (distToPlayer < currEventHorizon)
        {
            foreach (Transform child in CODTrans.parent)
            {
                if (child == CODTrans)
                {
                    continue;
                }
                float otherDistToPlayer = Vector3.Distance(child.position, playerRB.position);
                if (otherDistToPlayer < distToPlayer)
                {
                    return;
                }
            }
            // Eat
            Vector3 suctionDirection = gravityFrameController.FindFrameAlignedDirection(gravityFrameController.ClosestPointOnFramePlane, CODTrans.position - playerRB.position);
            vignette.intensity.value = (1f - (distToPlayer / currEventHorizon)) * .75f;
            if (distToPlayer < (currEventHorizon * .66f))
            {
                playerRB.AddForce(suctionDirection * (1 - (distToPlayer / (currEventHorizon * .66f))) * suction, ForceMode.Acceleration);
            }

            // Increase speed based on player distance to end
            float propPlayerDistToEnd = Mathf.Clamp01(Vector3.Distance(playerRB.position, MazeFrameSplines.EndPoint) / Vector3.Distance(MazeFrameSplines.StartPoint, MazeFrameSplines.EndPoint));
            float newMoveSpeed        = moveSpeed + maxSpeedFactor * moveSpeed * propPlayerDistToEnd;
            if (newMoveSpeed > currMoveSpeed)
            {
                currMoveSpeed = newMoveSpeed;
            }
        }
    }