Solved Analog Gauges irregular steps in speedo

Discussion in 'Mod Support' started by da_xx, Apr 22, 2022.

  1. da_xx

    da_xx
    Expand Collapse
    Banned

    Joined:
    Oct 15, 2021
    Messages:
    87
    Hey everyone,

    I'm creating an Volkswagen analog gauge, the problem is, until 60km/h there are 10km/h step after that they have 20km/h steps.

    Can i tell BeamNG that it should use a other "rotation" on a certain speed.


    I appreciate every help I get, thanks a lot!

    NewCarz-VW-T-Cross-EK-41.jpg
     
    • Agree Agree x 1
  2. NOCARGO

    NOCARGO
    Expand Collapse

    Joined:
    Apr 1, 2019
    Messages:
    1,498
    Hi,
    Sure, this can be done using LUA. Although affecting the actual prop (read 'needle') rotation would be too challenging without overwriting the core files rendering your mod unfit for the player. As many more jbeam parameters have become programmable inside the jbeam code the last year or 1.5 I don't think prop rotation is one of them. (might be wrong but don't think so)

    If you look at the jbeam code for the props you will see your speedo needle rotation is dependent on the "wheelspeed" electrics value.
    If you create a small LUA file in your mod that defines a custom electrics value like, lets say electrics.values.vwSpeedo or something,
    then you can play with this value using LUA code. All you need to do then is change the "wheelspeed" to "vwSpeedo" in your jbeam props section. Then now you could tell the lua file to multiply or divide your new electrics value in relation to the true electrics.values.wheelspeed.

    for example :
    if electrics.values.wheelspeed < 16.66 ( 60 km/h ) then electrics.values.vwSpeedo = (electrics.values.wheelspeed * 2) else electrics.values.vwSpeedo = electrics.values.wheelspeed end

    Now all you have to do is play with the calibration of your speed marks. So you 'imaginary' tell the car goes a certain speed when it actually doesn't but you tell the electrics.values to display a certain value thru the rotation of the electrics. Do you understand this ? :)

    By the way, as I'm thinking while typing there might be another way to do this too LOL :

    Well, I haven't ran the game since literally months now (I'm so freaking busy) but, modders hear this one, I think I like it :D
    Maybe you can use the same prop ("flexbodies") using two electrics inputs. Like, just copying down the prop line of the speedo and on the second one use the custom "vwSpeedo" electrics that are defined by a very simple lua file. Then you can use "wheelspeed" for one line and "vwSpeedo" for the other one. One goes to 16.66 and the other one goes from 16.66. I suspect these values might transition flawless (if it works), at least to the naked eye. :)

    Anyway, you seem to have a cool mod going here so if you don't understand all of this I might want to give it a shot one of these but if anyone else has the time on their hands these examples might get you somewhere :)

    edit : NO, I just realize that the second method won't work because the flexbody would still remain visible at zero value LOL
     
    • Like Like x 2
    • Agree Agree x 2
  3. da_xx

    da_xx
    Expand Collapse
    Banned

    Joined:
    Oct 15, 2021
    Messages:
    87
    Hii thx alot for your explanation.

    Im thankfull you answered and give me such a cleaver workaround :D

    i will tell you if it works

    I will try it as soon asap ! Yes i already thougt about the second idea my selfe and tried it but as you mentioned you will have two needles instead hahah
     
  4. da_xx

    da_xx
    Expand Collapse
    Banned

    Joined:
    Oct 15, 2021
    Messages:
    87
    Am i able to change the mutiplier value in LUA ? upload_2022-5-1_18-3-43.png
     
  5. NOCARGO

    NOCARGO
    Expand Collapse

    Joined:
    Apr 1, 2019
    Messages:
    1,498
    As far as I know no, that's what the 1st paragraph of my reply explains :
    I suppose one would be able to create a complete lua module (like for instance "props2") hah that allows the multiplier to be variable but that's just way too much wasted time and effort to achieve the goal. I would just go for custom electrics value as I mentioned :)
    Custom electrics.values just calls for a certain mathematical formula or a statement (if.. then..) that mathematically changes the value. I'll see if I can come up with something if you can't figure it out.
    --- Post updated ---
    Alright, I should be smacking the bed bugs for a long time now :)
    I think this one will work, tested on the 200BX and the marks seem to be corresponding.

    Code:
    -- This Source Code Form is subject to the terms of the bCDDL, v. 1.1.
    -- If a copy of the bCDDL was not distributed with this
    -- file, You can obtain one at http://beamng.com/bCDDL-1.1.txt
    
    local M = {}
    
    local function onInit()
     electrics.values.vwSpeedoLow = 0
     electrics.values.vwSpeedoHigh = 0
     electrics.values.vwSpeedo = 0
    end
    
    local function updateGFX(dt)
    electrics.values.vwSpeedoLow = electrics.values.wheelspeed
    electrics.values.vwSpeedoHigh = 8.3295 + (electrics.values.wheelspeed / 2)
     if electrics.values.wheelspeed < 16.66 then
        electrics.values.vwSpeedo = electrics.values.vwSpeedoLow
     else
        electrics.values.vwSpeedo = electrics.values.vwSpeedoHigh
     end  
    end
    
    -- public interface
    
    M.onInit      = onInit
    M.onReset     = onInit
    M.updateGFX = updateGFX
    
    return M
    
    In your mod vehicle folder create a folder called 'lua' and put the file I added below inside the lua folder. Now you possibly might need to calibrate the needle properly with the values in the jbeam props section. Also, in the props section you need to change "wheelspeed" to "vwSpeedo", don't forget this.
     

    Attached Files:

    • Like Like x 1
  6. da_xx

    da_xx
    Expand Collapse
    Banned

    Joined:
    Oct 15, 2021
    Messages:
    87

    Thx a lot for your fast answer i will try it and hold you up to date :D
     
  7. da_xx

    da_xx
    Expand Collapse
    Banned

    Joined:
    Oct 15, 2021
    Messages:
    87
    Thank U so much, it works perfect :D:D:D
     
    • Like Like x 1
  8. NOCARGO

    NOCARGO
    Expand Collapse

    Joined:
    Apr 1, 2019
    Messages:
    1,498
     
    • Like Like x 1
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice