Esempio n. 1
0
    void Update()
    {
        Vector3 target;


        bool canMove = InterfaceManager.CanCarMove();

        if (Input.GetMouseButton(0) && canMove)
        {
            target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        }
        else
        {
            target = transform.position;
        }
        Vector3 vel = Seek(transform.position, target);

        anim.speed = 0.8f * (vel.magnitude / onMotorwaySettings.maxVelocity);
        if (currentSettings.maxVelocity != 0f && currentSource != null)
        {
            currentSource.volume = Mathf.Clamp01(vel.magnitude / currentSettings.maxVelocity);
        }
        transform.position += vel * Time.deltaTime;
        // trackerTM.localPosition = vel*Time.deltaTime*ratioTM;
        if (vel.magnitude > 0 && Vector3.Distance(lastPos, transform.position) > distThreshold)
        {
            TimeManager.Instance.Progress();
        }
        lastPos = transform.position;
        if (Input.GetMouseButton(0) && canMove)
        {
            angle = Mathf.Atan2(vel.y, vel.x) * Mathf.Rad2Deg;
        }

        float driftAngle = Vector3.Angle(vel, vecDesired);

        if (driftAngle > driftingThreshold)
        {
            drifting = true;
        }
        else
        {
            drifting = false;
        }
        transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));
    }