コード例 #1
0
    private void FixedUpdate()
    {
        if (!dragging && !start)
        {
            velocity += Gravity.Acceleration();

            float time = Time.realtimeSinceStartup;

            // Get Triangle List
            List <Triangle> underWaterTriangles = Intersection.GetTrianglesUnderWater(ref triangles, ref vertices, transform, intersectPosition);

            // Get Volume
            float volumeUnderWater = VolumeCalculator.GetVolume(ref underWaterTriangles, transform, intersectPosition);

            if (UIText != null)
            {
                float totalVolumeRounded      = Mathf.Round(totalVolume * 100f) / 100f;
                float volumeUnderWaterRounded = Mathf.Round(volumeUnderWater * 100f) / 100f;
                UIText.text = transform.name + " - Total Volume:" + totalVolumeRounded + ", Volume Under Water: " + volumeUnderWaterRounded;
            }

            // Calculate drag from air or water
            float   dragDensity = volumeUnderWater > 0f ? densityWater : densityAir;
            Vector3 drag        = Drag.GetDragForce(coefficientOfDrag, dragDensity, velocity, area);
            velocity -= drag / mass;

            // Calculate Lift
            Vector3 bouyancy = Buoyancy.Calculate(transform, intersectPosition, volumeUnderWater, totalVolume);

            // velocity += lift;
            velocity += bouyancy / mass * Time.fixedDeltaTime;

            if (transform.position.y < ground.transform.position.y)
            {
                Vector3 currentPosition = transform.position;
                currentPosition.y  = ground.transform.position.y;
                transform.position = currentPosition;
                velocity           = Vector3.zero;
            }
            //velocity += Lift.CalculateLift(ref myTriangles, ref myVertices, transform, intersectPosition, totalVolume) / mass * Time.fixedDeltaTime;

            ApplyVelocity();
        }
    }