Ejemplo n.º 1
0
    public void CollisionCalibration()
    {
        Vector3    totalNormalForce = Vector3.zero;
        int        noOfCycles       = 0;
        RaycastHit hit = rayCaster.GetCollisionData(velocity, 0);

        do
        {
            //Add one cycle
            noOfCycles++;

            //Make adjustments to normalforce
            Vector3 normalForce = MeasureNormalForce();
            velocity         += normalForce;
            totalNormalForce += normalForce;

            //Look for new collisions
            hit = rayCaster.GetCollisionData(velocity, 0);
        }while (hit.collider != null && noOfCycles < 1000);

        velocity = PhysicsCalculator.CalculateFriction(velocity, totalNormalForce, staticFrictionCo);

        if (hit.collider == null)
        {
            transform.position += velocity * Time.deltaTime;
        }
    }