Exemple #1
0
    private void SetVelocity()
    {
        float projectedWorldVelocityMagnitude = _Car.GetProjectedWorldVelocity.magnitude;

        _Car.SetProjectedWorldVelocity(Vector3.ProjectOnPlane(_Car.GetProjectedWorldVelocity, _Car.GetCarManager.GetPhysics.GetInterpolatedNormal).normalized);
        _Car.SetProjectedWorldVelocity(_Car.GetProjectedWorldVelocity * projectedWorldVelocityMagnitude);

        if (_Car.GetLocalVelocity.z < _Car.GetCarManager.GetMaxStrigthVelocity && _Car.GetLocalVelocity.z > -(_Car.GetCarManager.GetMaxStrigthVelocity * 0.25f))
        {
            _Car.SetProjectedWorldVelocity(_Car.GetProjectedWorldVelocity + (_Car.GetProjectedForward * _Car.GetSpeedPerFrame * Time.fixedDeltaTime));
        }

        projectedWorldVelocityMagnitude = _Car.GetProjectedWorldVelocity.magnitude;
        _Car.SetProjectedWorldVelocity(Vector3.ProjectOnPlane(_Car.GetProjectedWorldVelocity, _Car.GetCarManager.GetPhysics.GetInterpolatedNormal).normalized);
        _Car.SetProjectedWorldVelocity(_Car.GetProjectedWorldVelocity * projectedWorldVelocityMagnitude);



        Vector3 localVelocity = Vector3.zero;

        localVelocity.x = Vector3.Dot(_Car.GetProjectedWorldVelocity, _Car.GetProjectedRight);
        localVelocity.y = Vector3.Dot(_Car.GetProjectedWorldVelocity, Vector3.Cross(_Car.GetProjectedRight, _Car.GetProjectedForward));
        localVelocity.z = Vector3.Dot(_Car.GetProjectedWorldVelocity, _Car.GetProjectedForward);
        _Car.SetLocalVelocity(localVelocity);

        if (localVelocity.x != 0)
        {
            _Car.SetProjectedWorldVelocity(_Car.GetProjectedWorldVelocity - (_Car.GetCarManager.GetSideWaysFriction * _Car.GetProjectedRight * Mathf.Sign(localVelocity.x) * Time.fixedDeltaTime));
        }
        if (localVelocity.z != 0)
        {
            _Car.SetProjectedWorldVelocity(_Car.GetProjectedWorldVelocity - (_Car.GetCarManager.GetStraightFriction * _Car.GetProjectedForward * Mathf.Sign(localVelocity.z) * Time.fixedDeltaTime));
        }
    }