Exemplo n.º 1
0
    void Update()
    {
        if (gameObject.GetComponent <TrafAIMotor>() != null)
        {
            //sono in guida automatica nello scenario urbano
            logi.guidaAutomatica = true;
            return;
        }
        logi.guidaAutomatica = false;

        float selfAlignmentTorque = 0f;

        foreach (var wheel in wheels)
        {
            if (wheel.isGrounded)
            {
                WheelHit hit;
                wheel.GetGroundHit(out hit);

                Vector3 left  = hit.point - (hit.sidewaysDir * tireWidth * 0.5f);
                Vector3 right = hit.point + (hit.sidewaysDir * tireWidth * 0.5f);

                Vector3 leftTangent = rb.GetPointVelocity(left);
                leftTangent -= Vector3.Project(leftTangent, hit.normal);

                Vector3 rightTangent = rb.GetPointVelocity(right);
                rightTangent -= Vector3.Project(rightTangent, hit.normal);

                float slipDifference = Vector3.Dot(hit.forwardDir, rightTangent) - Vector3.Dot(hit.forwardDir, leftTangent);

                selfAlignmentTorque += (0.5f * weightIntensity * slipDifference) / 2f;
            }
        }

        float forceFeedback = selfAlignmentTorque;



        //disable during autodrive mode
        if (TrackController.Instance.IsInAutoPath() || !(AppController.Instance.UserInput is SteeringWheelInputController))
        {
            if (logi != null)
            {
                logi.SetConstantForce(0);
                logi.SetDamperForce(0);
                logi.SetSpringForce(0, 0);
            }
        }
        else
        {
            if (logi != null)
            {
                logi.SetConstantForce((int)(forceFeedback * 10000f));
                logi.SetSpringForce(Mathf.RoundToInt(springSaturation * Mathf.Abs(forceFeedback) * 10000f), Mathf.RoundToInt(springCoeff * 10000f));
                logi.SetDamperForce(damperAmount);
            }
        }
    }
Exemplo n.º 2
0
    void Update()
    {
        float selfAlignmentTorque = 0f;

        foreach (var wheel in wheels)
        {
            if (wheel.isGrounded)
            {
                WheelHit hit;
                wheel.GetGroundHit(out hit);

                Vector3 left  = hit.point - (hit.sidewaysDir * tireWidth * 0.5f);
                Vector3 right = hit.point + (hit.sidewaysDir * tireWidth * 0.5f);

                Vector3 leftTangent = rb.GetPointVelocity(left);
                leftTangent -= Vector3.Project(leftTangent, hit.normal);

                Vector3 rightTangent = rb.GetPointVelocity(right);
                rightTangent -= Vector3.Project(rightTangent, hit.normal);

                float slipDifference = Vector3.Dot(hit.forwardDir, rightTangent) - Vector3.Dot(hit.forwardDir, leftTangent);

                selfAlignmentTorque += (0.5f * weightIntensity * slipDifference) / 2f;
            }
        }

        float forceFeedback = selfAlignmentTorque;

        //disable during autodrive mode
        if (TrackController.Instance.IsInAutoPath() || !(AppController.Instance.UserInput is SteeringWheelInputController))
        {
            if (logi != null)
            {
                logi.SetConstantForce(0);
                logi.SetDamperForce(0);
                logi.SetSpringForce(0, 0);
            }
        }
        else
        {
            if (logi != null)
            {
                if (!logi.getMasterSteeringWheel())
                {
                    logi.SetConstantForce((int)(forceFeedback * 10000f));
                    logi.SetSpringForce(Mathf.RoundToInt(springSaturation * Mathf.Abs(forceFeedback) * 10000f), Mathf.RoundToInt(springCoeff * 10000f));
                    logi.SetDamperForce(damperAmount);
                }
                else //this is if we have a mster steering wheel
                {
                    //

                    logi.SetConstantForce((int)(forceFeedback * 10000f));///DAVID HERE
                    logi.SetSpringForce(Mathf.RoundToInt(springSaturation * Mathf.Abs(forceFeedback) * 10000f), Mathf.RoundToInt(springCoeff * 10000f));
                    logi.SetDamperForce(damperAmount);

                    // computing the difference in steering angle
                    float steeringDifference = -((logi.GetSteerInput() - logi.GetSlaveSteeringInput()) * 2);
                    // Debug.Log(steeringDifference);
                    logi.SetSlaveConstantForce((int)(steeringDifference * 10000f));
                    logi.SetSlaveSpringForce(Mathf.RoundToInt(springSaturation * Mathf.Abs(steeringDifference) * 10000f), Mathf.RoundToInt(springCoeff * 10000f));
                    logi.SetSlaveDamperForce(damperAmount);
                }
            }
        }
    }