AngleVectorPlane() public static method

public static AngleVectorPlane ( Vector3 vector, Vector3 normal ) : float
vector Vector3
normal Vector3
return float
示例#1
0
    void FixedUpdate()
    {
        currentPipe.GetPlaneOfCurve(
            transform.position,
            ref centerTrackPointDirection,
            ref centerTrackPointPosition,
            ref progress
            );

        if (progress >= 1)
        {
            currentPipe = pipeSystem.SetupNextPipe();
        }
        //if (progress >= 1) currentPipe = currentPipe.nextPipe;

        // update vehicle direction
        Vector3 upVector = GetUpVector();

        // method 1
        //Quaternion vehicleRotation = Quaternion.LookRotation(centerTrackPointDirection, upVector);

        // method 2
        float      vehicleHeadingElevation   = Math3d.AngleVectorPlane(centerTrackPointDirection, upVector);
        Quaternion restrictedVehicleRotation = Quaternion.AngleAxis(vehicleHeadingElevation, Vector3.left);

        // method 3
        //Quaternion rotation = Quaternion.FromToRotation(vehicleObject.transform.forward, centerTrackPointDirection);
        //Vector3 vehicleRotationEuler = rotation.eulerAngles;
        //Debug.Log(vehicleRotationEuler.y);
        //vehicleRotationEuler.y = 0;
        //Quaternion restrictedVehicleRotation = Quaternion.Euler(vehicleRotationEuler);

        //
        //Vector3 rotatedForward = restrictedVehicleRotation * vehicleObject.transform.forward;
        //Quaternion vehicleRotation = Quaternion.LookRotation(rotatedForward, upVector);
        //vehicleRotation *= accumulatedYRot;
        //vehicleObject.transform.rotation = Quaternion.RotateTowards(vehicleObject.transform.rotation, vehicleRotation, Time.deltaTime * 300f);

        // apply force to move forward
        //avatarRigidbody.AddForce(centerTrackPointDirection.normalized * 10f, ForceMode.Force);
        //avatarRigidbody.AddForce(vehicleObject.transform.forward.normalized * 10f, ForceMode.Force);

        float currentPipeRadius = currentPipe.GetPipeRadiusByProgress(progress);

        // apply force to make avatar stick to wall
        //float magnitudeModifier = (currentPipeRadius - upVector.magnitude + 1f) * 10f;
        //avatarRigidbody.AddForce(-upVector * 20f / currentPipeRadius, ForceMode.Acceleration);

        //avatarRigidbody.AddForce(upVector.normalized * Gravity, ForceMode.Acceleration);
        //Debug.Log(avatar.GetComponent<Rigidbody>().velocity.magnitude);
        //if (upVector.magnitude < currentPipeRadius) avatarRigidbody.AddForce(new Vector3(0, -9.81f, 0), ForceMode.Acceleration);

        //// hover
        //Ray ray = new Ray(avatar.transform.position, -avatar.transform.up);
        //RaycastHit hit;
        //float hoverHeight = 1.0f;
        //float hoverForce = 20f;
        //if (Physics.Raycast(ray, out hit, hoverHeight))
        //{
        //    float proportionalHeight = (hoverHeight - hit.distance) / hoverHeight;
        //    Vector3 appliedHoverForce = upVector.normalized * proportionalHeight * hoverForce;
        //    avatar.GetComponent<Rigidbody>().AddForce(appliedHoverForce, ForceMode.Acceleration);
        //}

        // update avatar turning according to user input
        //UpdateAvatarRotation(centerTrackPointDirection, centerTrackPointPosition);
    }