How to create seperate inputs for twin engine car

Discussion in 'Content Creation' started by whoms't, Apr 19, 2020.

  1. whoms't

    whoms't
    Expand Collapse

    Joined:
    Apr 14, 2020
    Messages:
    20
    I'm making a twin engine covet. I've got the rear engine working, and with a torque converter connecting the engine to the rear differential it works well. the problem is when i give it a gearbox, it doesn't shift. i assume its because the game isn't set up to control 2 gearboxes separately. i don't know how to make it work, so any help would be appreciated
     
  2. Diamondback

    Diamondback
    Expand Collapse
    Vehicle Systems Lead
    BeamNG Team

    Joined:
    Apr 8, 2014
    Messages:
    1,958
    You would need to write your own lua code to do this and provide the game a new shiftLogic lua file.
    Take a look at the existing shiftLogic files to get an idea about what they do.
     
  3. whoms't

    whoms't
    Expand Collapse

    Joined:
    Apr 14, 2020
    Messages:
    20
    so could i modify one of the shiftlogic files to have different inputs or would i have to create a new powertrain type to do it
    --- Post updated ---
    so after poking around for a bit, heres what i think i need to do. first i make a shiftlogic file and put it in my modfolder/lua/controller. then i tell the jbeam of that gearbox to use that shiftlogic file as the controller. i also have to make an input_actions.json and map those inputs to what i put in the shiftlogic file. is that close to remotely correct?
     
  4. NOCARGO

    NOCARGO
    Expand Collapse

    Joined:
    Apr 1, 2019
    Messages:
    1,514
    That seems quite close to not so remotely correct as far as my experience goes :)

    edit remember in the jbeam files : the controller is not the same as the source (your shiftLogic in this case).
    the gearbox lua goes to "powertrain" section and the shiftLogic lua automatically finds the gearbox name.
    I'm telling this because the controller sections handles the vehicle controller lua (or other controller lua's) and is named "vehicleController". You can also wright your own vehicle controller if
    needed.
     
    #4 NOCARGO, Apr 20, 2020
    Last edited: Apr 20, 2020
  5. whoms't

    whoms't
    Expand Collapse

    Joined:
    Apr 14, 2020
    Messages:
    20
    So if I understand correctly, for my twin engine covet which I want to have a sequential gearbox in the rear would i:

    make a shiftlogic-sequentialgearbox file with different inputs

    Create input actions and map those to what I want in the shiftlogic

    Or would I:

    In the jbeam define the gearbox as a different type, like rear sequential gearbox

    Add a vehicle controller part for the mod that includes my new gearbox type

    Then make a shiftlogic file for that gearbox type with custom inputs

    To be clear I have no idea what I'm doing and I'm in way over my head so any help I get is appreciated
     
  6. NOCARGO

    NOCARGO
    Expand Collapse

    Joined:
    Apr 1, 2019
    Messages:
    1,514
    Ok let's look at this step by step because you are very close to your target.

    You got the engine working, right ? So you named it different already I suppose ? Because the chain of components starts here.


    1 engine > 2 clutch > 3 transmission > 3b transfercase (if needed) > 4 driveshaft > 5 differential

    It's sort of like that 2 ↑

    Ok, so the car already has a rear diff ? But I take you used a torque converter instead of a friction clutch ? Oh yeah you're
    going to use a dct, right ?

    But you have the engine working without renaming it ? Then let's ignore the above briefly.
    So you already gave it a gearbox without problems in the code, it spawned successfully, right ?

    Then > copy the gearbox lua, rename it (but simply to avoid mistake) such as dctGearboxCOVET.lua
    > place this in your mod files as you suggested vehicles/hatch/lua/powertrain/ . . .
    > copy the shiftLogic-dctGearbox.lua and likewise change to shiftLogic-dctGearboxCOVET.lua
    > place this in your mod files as you suggested vehicles/hatch/lua/controller/ . . .

    Now we just let them sit there having a chat haha !

    No , seriously, now you have to change your second gearbox name to "dctGearboxCOVET" in the jbeam file ("powertrain" section).

    Now your new shift logic file knows how to find your new gearbox file.

    Ok, the soup is starting to boil now, time to pay attention.

    Now you create input actions for your new gearbox. How ? This is my take :

    Rename the next functions in the new shift logic file :

    local function shift up()
    local function shift down()

    local function shiftToGearIndex()

    Remember to keep it simply and brief, let's say

    local function shift up2()
    local function shift down2()

    local function shiftToGearIndex2()

    Now, you need to rename the function thru out the whole file, so also below at bottom of file :

    M.shiftUp = shiftUp
    M.shiftDown = shiftDown
    M.shiftToGearIndex = shiftToGearIndex
    becomes
    M.shiftUp2 = shiftUp2
    M.shiftDown2 = shiftDown2
    M.shiftToGearIndex2 = shiftToGearIndex2

    Finally, double check if the original function is named anywhere else in this file.

    Last step : add the input actions now

    Go and have a peek at BeamNG.drive-0.19.0...../lua/ge/extensions/core/input/actions/vehicle

    DON'T EDIT THIS FILE as can be read on the top lines !

    instead find these lines and copy to your own input_actions.json

    "shiftUp"
    "shiftDown"
    "gearR"
    "gear1"
    "gear2"
    "gear3"
    "gear4"
    "gear5"
    "gear6"
    "gear7"
    "gear8"
    "gearN"

    Not only ↑ these words but their whole respective lines

    - RENAME those first words , let's say
    "shiftUp_b"
    "shiftDown_b"
    "gearR_b"
    "gear1_b"
    "gear2_b"
    "gear3_b"
    "gear4_b"
    "gear5_b"
    "gear6_b"
    "gear7_b"
    "gear8_b"
    "gearN_b"

    - SCROLL further horizontally down those lines and find the functions you renamed, so also rename them here.

    - FINALLY even farther to the right you will see "description" so name your new bindings as you wish to.

    input_actions.json goes to your mod files : vehicles/hatch/input_actions.json

    You're done ! :D

    I didn't test this, I just wrote it out and this would be my personal take on the matter, someone else might solve it differently.

    Cheers !

    edit I'm sorry I now see you want sequential gearbox, no worry, same procedure, just use sequential instead of dct files

    EDIT EDIT If you don't have the second engine working (anymore) save the code anyway and
    start making a new second engine (first abandoned part of my reply) and feel free to ask my advice. :)
     
    #6 NOCARGO, Apr 21, 2020
    Last edited: Apr 21, 2020
    • Like Like x 2
    • Informative Informative x 1
  7. whoms't

    whoms't
    Expand Collapse

    Joined:
    Apr 14, 2020
    Messages:
    20
    thanks a bunch for taking the time to write that out, it is really helpful. I've not been able to get it to work, and i think the reason is because in my inputActions.json I'm mapping the inputs to the wrong thing, because i dont know how to map them straight to the shiftlogic file. i assume i have to map it to something like what they are in the vehicle.json file but with mainController replaced with what my shiftlogic file is but i dont know what mine would be called.
     
  8. NOCARGO

    NOCARGO
    Expand Collapse

    Joined:
    Apr 1, 2019
    Messages:
    1,514
    Oh hang on, you might be right ! The function might have to be renamed in the mainController too and indeed in that case you need
    a custom mainController. I'll check it out rightaway.
    --- Post updated ---
    Yep, this seems to be the case !

    You need a custom vehicleController :

    and these need to be renamed too ( and probably thru the whole file but I would try to change only these first and see what happens)

    local function shiftUp()
    controlLogicModule.shiftUp()
    end

    local function shiftDown()
    controlLogicModule.shiftDown()
    end

    local function shiftToGearIndex(index)
    controlLogicModule.shiftToGearIndex(index)
    end

    Do you already have a separate (custom) vehicleController for your Covet ?

    By the way I think it would suffice to only rename these above and only the 'function' part.
    this way the controlLogicModule part sees the function as it was before renamed in the shiftLogic file.
    I hope you're still able to get a grip on the logic overall :) If everything is renamed : likewise, no problem
    imo.
     
  9. whoms't

    whoms't
    Expand Collapse

    Joined:
    Apr 14, 2020
    Messages:
    20
    ok, so what ive done is

    ive made a lua folder in my mod folder. in the lua folder there's a powertrain and a controller folder.

    inside the powertrain folder is a copy of the sequential gearbox lua, renamed to covetRearSequentialGearbox.lua

    inside the controller folder theres a copy of the vehicleController lua with these lines added in

    local function covetRearShiftUp()
    controlLogicModule.covetRearShiftUp()
    end

    local function covetRearShiftDown()
    controlLogicModule.covetRearShiftDown()
    end

    local function covetRearShiftToGearIndex(index)
    controlLogicModule.covetRearShiftToGearIndex(index)
    end

    M.covetRearShiftUp = covetRearShiftUp
    M.covetRearShiftDown = covetRearShiftDown
    M.covetRearShiftToGearIndex = covetRearShiftToGearIndex

    this makes the main controller execute M.covetRearShiftUp or Down or gearIndex in my shiftLogic-covetRearSequentialGearbox.lua which is a renamed copy of the sequential gearbox shiftlogic in my mods controller folder

    the shiftlogic file has all the shiftUp shiftDown and shifttogearindex renamed to covetRearxxxxx, but i think it would work also if only the M. values were changed to M.covetRearxxxxxx.

    then in my inputactions.json i have covetRearShiftUp mapped to "controller.mainController.covetRearShiftUp()" and so on

    then in my inputmaps folder in the keyboard.json file i have a key mapped to covetRearShiftUp and another for covetRearShiftDown

    this seems like it should work to me, but it doesnt.
    in game the car spawns fine, and theres no errors in the console when its spawned. the gearbox shows up in the correct spot on the powertrain as its own type, but when i hit the key to shift, i get this error message in the console

    *** FATTA LUA ERROR: vehicles/hatch//lua/controller/vehicleController.lua:517: attempt to call field 'covetRearShiftUp' (a nil value)
    ======= Stack Traceback >> START>>
    (1) Lua field 'covetRearShiftUp' at file 'vehicles/hatch//lua/controller/vehicleController.lua:517'
    Local variables:
    (*temporary) = nil
    (*temporary) = nil
    (*temporary) = string: attempt to call field 'covetRearShiftUp' (a nil value)
    (2) main chunk of string at line 1
    -------------- << END <<
    *** while executing this line: controller.mainController.covetRearShiftUp()
    *** in chunk: string


    i think this means that the main controller doesnt know what to do with the input but i dont know what else i would need to add in the main controller for it to be able to work. i thought that this line:local controlLogicModuleName = "controller/shiftLogic-" .. controlLogicName combined with the bits i added wouldve worked, but i guess not. any ideas?
     
  10. NOCARGO

    NOCARGO
    Expand Collapse

    Joined:
    Apr 1, 2019
    Messages:
    1,514
    I am going to answer first before I read everything you posted, because the console output is telling me that you didn't
    create a custom vehicle controller, is that right ?
     
  11. whoms't

    whoms't
    Expand Collapse

    Joined:
    Apr 14, 2020
    Messages:
    20
    i modified a copy of vehiclecontroller lua in my controller folder, is that the correct thing to do?
     
  12. NOCARGO

    NOCARGO
    Expand Collapse

    Joined:
    Apr 1, 2019
    Messages:
    1,514
    No, you need to rename it and your gearbox and/or engine jbeams need to receive that new name but wait, I'm going to
    edit your post and fill it with comments..
    --- Post updated ---
    --- Post updated ---
    Also your new gearbox needs the covetVehicleController instead of vehicleController.
     
  13. whoms't

    whoms't
    Expand Collapse

    Joined:
    Apr 14, 2020
    Messages:
    20
    ok so i made the changes, and now at least something is happening

    so when i put the covetVehicleController in the main hatch.jbeam there is an error in the console because i cant have 2 main type controllers on the same vehicle. if i comment out the vehicleController part the car works the same as it did before, except now the actions i have assigned to rear shift are shifting the front gearbox, i assume because in the covetVehicleController the local function points the covetRearShiftUp to the controlLogicModule.ShiftUp. its not what i want it to do but at least its doing something

    if i change the M.type to something else, like secondary, i can put it in the main hatch.jbeam with no errors, but when i try add a controller section to the gearbox it has a duplicate controller error. i think it means i should only have the controller in the gearbox jbeam, or im typing it in wrong, but im not sure

    i think the main problem i have now is when i change the M.type of the covetVehicleController my inputactions.json doesnt seem to be able to find it, probably because im typing it in wrong. i tried changing the M.type to secondary and mapped my inputs to controller.secondaryController.covetRearShiftUp, but it didnt seem to work.
     
  14. NOCARGO

    NOCARGO
    Expand Collapse

    Joined:
    Apr 1, 2019
    Messages:
    1,514
    Also your new gearbox needs the
    Alright, best not to start shooting random bullets around the files :)
    Stick to the initial result after my last instructions and lets discuss from there.
    Now, normally the game accepts two vehicle controllers and switches automatically were needed. I can prove that by showing console
    output. Anyway, I think yours is refused because I think that you are using the second engine running thru the original engine's files
    too. It's about the temporary ignored part of my previous message :

    Remember ?

    Ok, better tell me no how your second engine works. You copied jbeam, adapted slots and they are running in sync ?
    --- Post updated ---
    On a side note :

    This I created a small year ago in 0.15, just cranked it up for you, oh long time no see :D

    It has no drive train but I wrote it's own electrics streams so it could have its own instrument panel. As you can
    see it has its own controls too. The gauge next to the RPM gauge is currently assigned to cylinder head temperature
    I believe.



    So I know pretty sure you can achieve your goal but it will take some testing.

    Lately I'm working a lot on my latest mod CTK 28-series, which will be published, and it suddenly comes to my mind that
    probably your whole vehicle is going to have to use that custom vehicle controller. This way you expand that controller
    until it's able to manage al new features.

    Anyway, let me know how you engine is set up :)

    Cheers
     
  15. whoms't

    whoms't
    Expand Collapse

    Joined:
    Apr 14, 2020
    Messages:
    20
    The rear engine is only set up in powertrain.
    So I just added a slot in the body jbeam for rear engine, added a rear engine in new jbeam in powertrain and added bits off there.

    The engine responds to the regular throttle input and so does the clutch, but there are problems that doing what you did with yours would fix, like the engine not turning on or off.

    Would I have to make my own engine and clutch types like with the gearbox and change mapping so they can all work separately to the front parts?
     
  16. NOCARGO

    NOCARGO
    Expand Collapse

    Joined:
    Apr 1, 2019
    Messages:
    1,514
    I think you can go both ways : or you go for total sync, or you go for total separation, but working hybrid between would become messy.
     
  17. whoms't

    whoms't
    Expand Collapse

    Joined:
    Apr 14, 2020
    Messages:
    20
    quick question:
    when i have both controllers in like this
    "controller": [
    ["fileName"],
    ["vehicleController", {}],
    ["covetVehicleController", {}],
    ],
    i get a console message saying
    Found more that one main controller, 1: 'covetVehicleController', 2: 'vehicleController', unloading the first one...
    does this mean i have to change the M.type of mine, and if so how do i map my input_actions to it?
     
  18. NOCARGO

    NOCARGO
    Expand Collapse

    Joined:
    Apr 1, 2019
    Messages:
    1,514
    No, basically this is the right console output. It's what I meant before when I said that I can show you thru the console output that it works with more controllers in your mod.

    What exactly do you mean by changing M.type ? Oh you mean the head of the lua file(s) ? Not at all, that would mess things up. :)

    Am I right to assume that your second engine is physically present in the vehicle when spawned (nodes,beams and mesh) ?
     
  19. whoms't

    whoms't
    Expand Collapse

    Joined:
    Apr 14, 2020
    Messages:
    20
    yep, it has everything, shows up in powertrain as well, makes noise and power

    ok so im not understanding here.
    i added some new parts to my lua and a new input action so when i hit a key the rear engine turns on. if i comment out the vehicleController in the main jbeam and just leave the covetVehicleController it works perfectly. if i add the vehicleController back in it unloads mine and my inputs dont do anything because theyre not defined in the vehicleController lua.
    also i think im adding the controllers to the individual parts wrong because i get a
    found duplicate controller of name 'covetVehicleController' error
     
    #19 whoms't, Apr 23, 2020
    Last edited: Apr 23, 2020
  20. NOCARGO

    NOCARGO
    Expand Collapse

    Joined:
    Apr 1, 2019
    Messages:
    1,514
    Seems like you're starting to get the hang of it ! :D
    It's fine, leave the original vehicleController out (just comment out). And base everything on your new one. The wiser you get, the
    more you can expand it. :)

    Yes it seems this you still need to fix. Is it fatal and red colored ?

    So the engine is running and starting separately ? Great, how about the second drive train ? Is something coming alive yet ?
     
  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