900hasse / FS22_REAwheels

Farming Simulator 22, wheels
34 stars 2 forks source link

Offroad and Street tireTypes act as Mud #20

Closed Kubimate closed 1 year ago

Kubimate commented 1 year ago

Hi, I tried to change some values in friction coefs (in global parameters section) to my liking, so I set 1.1 for every tire type on every ground type, but set 0.1 for street tires on road ground, just to check and see what happens.

What I should get is to have a car with any tire type have a good friction on every ground type, but a car with street tyres slip like mad on asphalt. What I get is no slip at all, everything has good friction on every surface.

So I changed street on road back to 1.1, and set mud on road to 0.1. I should see basically every tractor to slip on roads, but now every vehicle (with exception of crawlers) has low friction on road ground type.

Now I have a vehicle with Street tyre type having low friction on Road ground type, despite setting 1.1 in global parameters section, same thing with Offroad.

These are my settings:

    -------------------------------------
    -- MUD
    -- TireType on different groundtypes
    SnowCoeffFactor = 0.5;
    REAwheels:SetFrictionCoeff(TireTypeMUD,ROAD,0.1,0.1,SnowCoeffFactor);
    REAwheels:SetFrictionCoeff(TireTypeMUD,HARD_TERRAIN,1.1,1.1,SnowCoeffFactor);
    REAwheels:SetFrictionCoeff(TireTypeMUD,SOFT_TERRAIN,1.1,1.1,SnowCoeffFactor);
    REAwheels:SetFrictionCoeff(TireTypeMUD,FIELD,1.1,1.1,SnowCoeffFactor);
    -- Sink parameters (percentage)
    REAwheels.TireTypeMaxSinkFrictionReduced[TireTypeMUD] = 35;
    REAwheels.TireTypeSinkStuckLevel[TireTypeMUD] = 95;
    REAwheels.TireTypeSinkPerMeterSpinning[TireTypeMUD] = 0.04;
    -- Min rolling coefficient
    REAwheels.TireTypeMinRollingCoeff[TireTypeMUD] = 0.04;
    -------------------------------------
    -- OFFROAD
    -- TireType on different groundtypes
    SnowCoeffFactor = 0.7;
    REAwheels:SetFrictionCoeff(TireTypeOFFROAD,ROAD,1.1,1.1,SnowCoeffFactor);
    REAwheels:SetFrictionCoeff(TireTypeOFFROAD,HARD_TERRAIN,1.1,1.1,SnowCoeffFactor);
    REAwheels:SetFrictionCoeff(TireTypeOFFROAD,SOFT_TERRAIN,1.1,1.1,SnowCoeffFactor);
    REAwheels:SetFrictionCoeff(TireTypeOFFROAD,FIELD,1.1,1.1,SnowCoeffFactor);
    -- Sink parameters (percentage)
    REAwheels.TireTypeMaxSinkFrictionReduced[TireTypeOFFROAD] = 40;
    REAwheels.TireTypeSinkStuckLevel[TireTypeOFFROAD] = 90;
    REAwheels.TireTypeSinkPerMeterSpinning[TireTypeOFFROAD] = 0.03;
    -- Min rolling coefficient
    REAwheels.TireTypeMinRollingCoeff[TireTypeOFFROAD] = 0.03;
    -------------------------------------
    -- STREET
    -- TireType on different groundtypes
    SnowCoeffFactor = 0.5;
    REAwheels:SetFrictionCoeff(TireTypeSTREET,ROAD,1.1,1.1,SnowCoeffFactor);
    REAwheels:SetFrictionCoeff(TireTypeSTREET,HARD_TERRAIN,1.1,1.1,SnowCoeffFactor);
    REAwheels:SetFrictionCoeff(TireTypeSTREET,SOFT_TERRAIN,1.1,1.1,SnowCoeffFactor);
    REAwheels:SetFrictionCoeff(TireTypeSTREET,FIELD,1.1,1.1,SnowCoeffFactor);
    -- Sink parameters (percentage)
    REAwheels.TireTypeMaxSinkFrictionReduced[TireTypeSTREET] = 50;
    REAwheels.TireTypeSinkStuckLevel[TireTypeSTREET] = 80;
    REAwheels.TireTypeSinkPerMeterSpinning[TireTypeSTREET] = 0.02;
    -- Min rolling coefficient
    REAwheels.TireTypeMinRollingCoeff[TireTypeSTREET] = 0.02;
    -------------------------------------
    -- CRAWLER
    -- TireType on different groundtypes
    SnowCoeffFactor = 0.6;
    REAwheels:SetFrictionCoeff(TireTypeCRAWLER,ROAD,1.1,1.1,SnowCoeffFactor);
    REAwheels:SetFrictionCoeff(TireTypeCRAWLER,HARD_TERRAIN,1.1,1.1,SnowCoeffFactor);
    REAwheels:SetFrictionCoeff(TireTypeCRAWLER,SOFT_TERRAIN,1.1,1.1,SnowCoeffFactor);
    REAwheels:SetFrictionCoeff(TireTypeCRAWLER,FIELD,1.1,1.1,SnowCoeffFactor);
    -- Sink parameters (percentage)
    REAwheels.TireTypeMaxSinkFrictionReduced[TireTypeCRAWLER] = 40;
    REAwheels.TireTypeSinkStuckLevel[TireTypeCRAWLER] = 95;
    REAwheels.TireTypeSinkPerMeterSpinning[TireTypeCRAWLER] = 0.03;
    -- Min rolling coefficient
    REAwheels.TireTypeMinRollingCoeff[TireTypeCRAWLER] = 0.1;

It looks like Street and Offroad tire type are using a default Mud tiretype values. Crawler behaves properly.

I have checked what "tireTrackAtlasIndex" is used and also made sure that I'm really using correct tire type by adding debug print output (TireTypeBasedOnTireTrackIndex + TireTypeName), and set DebugGroundType to true to see if I'm indeed driving on a road.

it_slips

Only mods I have enabled are REA wheels, easy development controls and a car with 3 tyre configs for easier testing.

TL;DR My config says street tires should NOT slip on roads, and Mud tires should, but both do.

900hasse commented 1 year ago

Hello!

The friction is also calculated based on the size of the tire.

A wider and a larger diameter tire has more friction then a smaller one, this makes smaller wheels like car wheels slip more.

Let’s say you have two tires of the same size, then all would depend on the “friction coefs”.

Add to this that smaller diameter wheels have got a larger rolling resistance then larger diameter that the wheel has to overcome.

See row 483-497 for the friction calculation.

Are you sure that the parameters for the wheel in your vehicle is correct?

//Hans

Från: Kubimaté @.> Skickat: den 19 mars 2023 01:08 Till: 900hasse/FS22_REAwheels @.> Kopia: Subscribed @.***> Ämne: [900hasse/FS22_REAwheels] Offroad and Street tireTypes act as Mud (Issue #20)

Hi, I tried to change some values in friction coefs (in global parameters section) to my liking, so I set 1.1 for every tire type on every ground type, but set 0.1 for street tires on road ground, just to check and see what happens.

What I should get is to have a car with any tire type have a good friction on every ground type, but a car with street tyres slip like mad on asphalt. What I get is no slip at all, everything has good friction on every surface.

So I changed street on road back to 1.1, and set mud on road to 0.1. I should see basically every tractor to slip on roads, but now every vehicle (with exception of crawlers) has low friction on road ground type.

Now I have a vehicle with Street tyre type having low friction on Road ground type, despite setting 1.1 in global parameters section, same thing with Offroad.

These are my settings:

    -------------------------------------
    -- MUD
    -- TireType on different groundtypes
    SnowCoeffFactor = 0.5;
    REAwheels:SetFrictionCoeff(TireTypeMUD,ROAD,0.1,0.1,SnowCoeffFactor);
    REAwheels:SetFrictionCoeff(TireTypeMUD,HARD_TERRAIN,1.1,1.1,SnowCoeffFactor);
    REAwheels:SetFrictionCoeff(TireTypeMUD,SOFT_TERRAIN,1.1,1.1,SnowCoeffFactor);
    REAwheels:SetFrictionCoeff(TireTypeMUD,FIELD,1.1,1.1,SnowCoeffFactor);
    -- Sink parameters (percentage)
    REAwheels.TireTypeMaxSinkFrictionReduced[TireTypeMUD] = 35;
    REAwheels.TireTypeSinkStuckLevel[TireTypeMUD] = 95;
    REAwheels.TireTypeSinkPerMeterSpinning[TireTypeMUD] = 0.04;
    -- Min rolling coefficient
    REAwheels.TireTypeMinRollingCoeff[TireTypeMUD] = 0.04;
    -------------------------------------
    -- OFFROAD
    -- TireType on different groundtypes
    SnowCoeffFactor = 0.7;
    REAwheels:SetFrictionCoeff(TireTypeOFFROAD,ROAD,1.1,1.1,SnowCoeffFactor);
    REAwheels:SetFrictionCoeff(TireTypeOFFROAD,HARD_TERRAIN,1.1,1.1,SnowCoeffFactor);
    REAwheels:SetFrictionCoeff(TireTypeOFFROAD,SOFT_TERRAIN,1.1,1.1,SnowCoeffFactor);
    REAwheels:SetFrictionCoeff(TireTypeOFFROAD,FIELD,1.1,1.1,SnowCoeffFactor);
    -- Sink parameters (percentage)
    REAwheels.TireTypeMaxSinkFrictionReduced[TireTypeOFFROAD] = 40;
    REAwheels.TireTypeSinkStuckLevel[TireTypeOFFROAD] = 90;
    REAwheels.TireTypeSinkPerMeterSpinning[TireTypeOFFROAD] = 0.03;
    -- Min rolling coefficient
    REAwheels.TireTypeMinRollingCoeff[TireTypeOFFROAD] = 0.03;
    -------------------------------------
    -- STREET
    -- TireType on different groundtypes
    SnowCoeffFactor = 0.5;
    REAwheels:SetFrictionCoeff(TireTypeSTREET,ROAD,1.1,1.1,SnowCoeffFactor);
    REAwheels:SetFrictionCoeff(TireTypeSTREET,HARD_TERRAIN,1.1,1.1,SnowCoeffFactor);
    REAwheels:SetFrictionCoeff(TireTypeSTREET,SOFT_TERRAIN,1.1,1.1,SnowCoeffFactor);
    REAwheels:SetFrictionCoeff(TireTypeSTREET,FIELD,1.1,1.1,SnowCoeffFactor);
    -- Sink parameters (percentage)
    REAwheels.TireTypeMaxSinkFrictionReduced[TireTypeSTREET] = 50;
    REAwheels.TireTypeSinkStuckLevel[TireTypeSTREET] = 80;
    REAwheels.TireTypeSinkPerMeterSpinning[TireTypeSTREET] = 0.02;
    -- Min rolling coefficient
    REAwheels.TireTypeMinRollingCoeff[TireTypeSTREET] = 0.02;
    -------------------------------------
    -- CRAWLER
    -- TireType on different groundtypes
    SnowCoeffFactor = 0.6;
    REAwheels:SetFrictionCoeff(TireTypeCRAWLER,ROAD,1.1,1.1,SnowCoeffFactor);
    REAwheels:SetFrictionCoeff(TireTypeCRAWLER,HARD_TERRAIN,1.1,1.1,SnowCoeffFactor);
    REAwheels:SetFrictionCoeff(TireTypeCRAWLER,SOFT_TERRAIN,1.1,1.1,SnowCoeffFactor);
    REAwheels:SetFrictionCoeff(TireTypeCRAWLER,FIELD,1.1,1.1,SnowCoeffFactor);
    -- Sink parameters (percentage)
    REAwheels.TireTypeMaxSinkFrictionReduced[TireTypeCRAWLER] = 40;
    REAwheels.TireTypeSinkStuckLevel[TireTypeCRAWLER] = 95;
    REAwheels.TireTypeSinkPerMeterSpinning[TireTypeCRAWLER] = 0.03;
    -- Min rolling coefficient
    REAwheels.TireTypeMinRollingCoeff[TireTypeCRAWLER] = 0.1;

It looks like Street and Offroad tire type are using a default Mud tiretype values. Crawler behaves properly.

I have checked what "tireTrackAtlasIndex" is used and also made sure that I'm really using correct tire type by adding debug print output (TireTypeBasedOnTireTrackIndex + TireTypeName), and set DebugGroundType to true to see if I'm indeed driving on a road.

https://user-images.githubusercontent.com/92585093/226146022-24f55414-c454-4c4f-bd31-046c4b2a455b.jpg

Only mods I have enabled are REA wheels, easy development controls and a car with 3 tyre configs for easier testing.

TL;DR My config says street tires should NOT slip on roads, and Mud tires should, but both do.

— Reply to this email directly, view it on GitHub https://github.com/900hasse/FS22_REAwheels/issues/20 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AXLRS63OICJUUWXWOCA4HC3W4ZE5VANCNFSM6AAAAAAV7YI5IM . You are receiving this because you are subscribed to this thread. https://github.com/notifications/beacon/AXLRS66TK5C3UH7O7Q3TXFDW4ZE5VA5CNFSM6AAAAAAV7YI5IOWGG33NNVSW45C7OR4XAZNFJFZXG5LFVJRW63LNMVXHIX3JMTHGCMUXBE.gif Message ID: @. @.> >

Kubimate commented 1 year ago

Are you sure that the parameters for the wheel in your vehicle is correct?

To be sure, I set my tires (street, offroad and mud configurations) to have the same physics parameters: radius="0.38" width="0.3"

but still, no matter what Offroad and Street tire friction coeffs I set, in-game they behave as it's set for Mud. Also this is not only a problem in my vehicle's settings - vanilla vehicles has the same problem. I've tested Lizard Pickup 2017 (street), any tractor (mud) - street behaves as mud.

rLy07 commented 1 year ago

I meant to open a new bug report for this but this might be relevant to this. I believe the rolling resistance calculation is wrong. Seems like the calculation for the rolling coefficient and resistance is from this wiki article. There it says that Crr = sqrt(z/d) which is correct in the code from section 547 (also for sideway resistance):

local ActWheelRollConf = math.sqrt(ActWheelSink/(ActWheeleRadius*2));

Then the calculation for the rolling resistance force

local ActWheelRollForce = math.max(ActWheelRollConf*(wheel.SmootheWheelLoad/ActWheeleRadius),MinForce);

This seems to be the line just under the above on the wiki F=Nb/r. Where the wiki states that b=rolling coefficient but it's different from Crr. So Crr shouldn't be substituted as 'b'. The article continues to mention that this formulae comes from a discredited "Coulomb's law" and 'b' can be solved by b=Crr*r. Based on this, the formulae should be only F=N*Crr which is mentioned just above the previous section on the wiki page. so:

local ActWheelRollForce = math.max((ActWheelRollConf*wheel.SmootheWheelLoad),MinForce);

After changing this there's a huge difference for small wheel vehicles like fork lifts. Before changing it they can barely move 3km/h, after changing it can reach their top speed at 13km/h. Haven't really noticed a difference for larger wheels.

Kubimate commented 1 year ago

@rLy07 As far as your suggested change indeed helps with smaller wheels, it does not seem to have anything to do with my problem. Could you please try this:

line 202 REAwheels:SetFrictionCoeff(TireTypeMUD,ROAD,1.0,0.95,SnowCoeffFactor); change to: REAwheels:SetFrictionCoeff(TireTypeMUD,ROAD,0.1,0.1,SnowCoeffFactor);

this only change should make mud tires have low friction on roads (and concrete), but you'll find that every vehicle (excluding crawlers) have low friction on those surfaces. Tried this with REA wheels as only loaded mod.

Also, I've tried to change Function to determine which tireType based on tireTrackAtlasIndex section from line 697 as follows:

function REAwheels:DetermineTireType(tireTrackAtlasIndex)
    -- Constants to use for each tireTypeName
    local TireTypeMUD = "mud";
    local TireTypeOFFROAD = "offRoad";
    local TireTypeSTREET = "street";
    local TireTypeCRAWLER = "crawler";
    -- Value to return
    local tireTypeName = TireTypeSTREET;
    -- Check tiretrackindex to see if value present
    if tireTrackAtlasIndex ~= nil then
        -- Check number to determine which tiretypename
        if tireTrackAtlasIndex == 0 then
            tireTypeName = TireTypeSTREET;
        elseif tireTrackAtlasIndex == 1 then
            tireTypeName = TireTypeSTREET;
        elseif tireTrackAtlasIndex == 2 then
            tireTypeName = TireTypeSTREET;
        elseif tireTrackAtlasIndex == 3 then
            tireTypeName = TireTypeSTREET;
        elseif tireTrackAtlasIndex == 4 then
            tireTypeName = TireTypeSTREET;
        elseif tireTrackAtlasIndex == 5 then
            tireTypeName = TireTypeSTREET;
        elseif tireTrackAtlasIndex == 6 then
            tireTypeName = TireTypeSTREET;
        elseif tireTrackAtlasIndex == 7 then
            tireTypeName = TireTypeSTREET;
        elseif tireTrackAtlasIndex == 8 then
            tireTypeName = TireTypeSTREET;
        elseif tireTrackAtlasIndex == 9 then
            tireTypeName = TireTypeSTREET;
        elseif tireTrackAtlasIndex == 10 then
            tireTypeName = TireTypeSTREET;
        elseif tireTrackAtlasIndex == 11 then
            tireTypeName = TireTypeSTREET;
        elseif tireTrackAtlasIndex == 12 then
            tireTypeName = TireTypeSTREET;
        elseif tireTrackAtlasIndex == 13 then
            tireTypeName = TireTypeSTREET;
        elseif tireTrackAtlasIndex == 14 then
            -- Not used
            tireTypeName = TireTypeSTREET;
        elseif tireTrackAtlasIndex == 15 then
            -- Not used
            tireTypeName = TireTypeSTREET;
        else
            tireTypeName = TireTypeSTREET;
        end
        -- Return tireType
        return WheelsUtil.getTireType(tireTypeName),tireTypeName;
    end
    -- Return tireType
    return 0,"Nothing found";
end

My custom debug print says everything is street, but still no change in handling - everythings on mud tires appearently, and settings for offroad and street are effectively useless, which for me defeats the purpose of this mod unfortunately.

rLy07 commented 1 year ago

@Kubimate I thought it's relevant because if the underlying calculation is wrong it can skew the result that you are trying to achieve. Anyway, I got interested and decided to reproduce your setup and I think I figured it out the issue. It's in the UpdateTireType function: line 809:

if TireTypeBasedOnTireTrackIndex ~= wheel.tireType and not wheel.tireType == TireTypeCRAWLER then

changing to this seems to fix it:

if TireTypeBasedOnTireTrackIndex ~= wheel.tireType and not (wheel.tireType == TireTypeCRAWLER) then

before this the tiretype isn't changed properly (mud tires are the default maybe?) except for tracked vehicles. Also possible fix is to remove the "not" and change the == to ~=.

Did notice some other things as well. Some vehicles detect the ground type differently depending on the wheels. I don't know where this comes from. 20230330200426_1

20230330200504_1

This one is weird, the picture shows all the same but ingame the first 2 wheels flickers between road and hard surface when moving. 20230330200515_1

Kubimate commented 1 year ago

@rLy07 Thank you! Both your fixes add up to make this mod usable again.

As to this switching ground types I can confirm I see the same thing, but it's hard to tell if it causes any problems in normal gameplay, as those affected wheels are rather small, non-drive and may be under minimum radius to be affected by friction and sink calculations. Anyways, I would open a separate ticket for this bug.