[SOLVED] Getting engine RPM in GELua

Discussion in 'Programming' started by Firepal3D, Apr 3, 2024.

  1. Firepal3D

    Firepal3D
    Expand Collapse

    Joined:
    Mar 26, 2022
    Messages:
    27
    Hello beamers and Cadillacs.
    I've been thinking about arcade-y camera for BeamNG, and something I think might work to good effect is camera shaking that depends on vehicle revving at a standstill.

    I already know how I would implement this.
    1. Have a decent smooth noise function that outputs a 3-vector (I already have this)
    2. Multiply that by the RPM of the vehicle's motor (or its rolling average)
    3. Multiply that by a "stand-stillness" value that is basically the absolute inverse of velocity,
    i.e. min(0.0,(20.0-abs(vel))/20.0) if 20kmh is considered to be "not standing still at all" :p


    I don't know if I looked in the wrong places, but I have no idea how to get the vehicle RPM.
    I think cameras are part of GE Lua... Doesn't help me narrow it down though.
     
  2. daniel-w

    daniel-w
    Expand Collapse
    BeamNG Team

    Joined:
    Jan 28, 2017
    Messages:
    282
    I've not messed around with camera's all that much, but there's some interesting things in ge/extensions/core/camera.lua.
    And you are correct, the camera's are part of GE Lua. You can look at all the different camera modes in ge/extensions/core/cameraModes.

    In order to get the engine RPM, you'll have to retreive that from the vehicle Lua. You can get the RPM via the following VLua:
    Code:
    local rpm = electrics.values["rpm"]
    
    (There are also other ways, just search in "lua/vehicle" for "rpm =".

    You can then forward this to GELua via: https://documentation.beamng.com/modding/programming/virtualmachines/#communication
    I also recommend giving the whole thing a read, it doesn't take too long, and it has some really good information.
     
    • Like Like x 1
  3. Firepal3D

    Firepal3D
    Expand Collapse

    Joined:
    Mar 26, 2022
    Messages:
    27
    You are awesome. That link got me understanding the Lua system a lot better and I got it working.
    For future reference, here is what I did to retrieve RPM:
    Code:
    cmd_vlua = "obj:queueGameEngineLua('rpm_orbit =' .. electrics.values.rpm)"
    data.veh:queueLuaCommand(cmd_vlua)
    The RPM was then placed into rpm_orbit, a global Lua variable accessible to GELua.
    For safety, I pre-initialized rpm_orbit to 0 in the camera's init function.
    --- Post updated ---
    Aaaand here's what this looks like right now.
     
  4. stenyak

    stenyak
    Expand Collapse
    Programmer & Global Moderator
    BeamNG Team

    Joined:
    Aug 6, 2012
    Messages:
    1,996
    Thanks a lot @vulcan-dev for sharing your knowledge in the forums!
    @Firepal3D or anyone else reading those documents, specially if you are new to modding and have any kind of feedback for the documentation, please feel free to ping me. Whether it's too high level, or too low level, or missing something obvious, etc - any kind of feedback is welcome :)
     
    • Like Like x 2
  5. Neverless

    Neverless
    Expand Collapse

    Joined:
    Sep 18, 2016
    Messages:
    227
    Ok

    1. Why is it named Virtual Machines (rhetorical)? If i would have went looking for exactly what is documented there, i would have never thought of searching for Virtual Machines. I mean it seems to be the correct term, i just wouldnt have thought of that. Not that i have a better name either

    2. Is it possible to PR to the documentation? So that the community could come together to expand it? eg https://docs.beammp.com/scripting/server-reference, thats basically compiled from a github repo
     
  6. stenyak

    stenyak
    Expand Collapse
    Programmer & Global Moderator
    BeamNG Team

    Joined:
    Aug 6, 2012
    Messages:
    1,996
    "Virtual Machine" is a common terminology used when talking about interpreters that are based on an byte-code language, as is the case with LuaJIT (the interpreter we use to run Lua source code).
    It's a pretty appropriate term, and also helps to reason about them as isolated invironments (rather than as threads that might have easy thread-sharing abilities, which they do not).
    We would need to check legal and technical implications of moving/mirroring the associated repositories to a platform like github or similar 3rd party services. Thanks for the suggestion, we'll consider options (although I cannot guarantee anything).

    For now you can post at https://www.beamng.com/threads/new-beamng-drive-documentation.77939/ . I already asked the relevant people to include this link in the documentation footer, they'll do it in a few weeks time :)
     
    • Like Like x 1
    • Agree Agree x 1
  7. Firepal3D

    Firepal3D
    Expand Collapse

    Joined:
    Mar 26, 2022
    Messages:
    27
    Cameras are probably at the intersection point of "being useful" and "having little documentation" in BeamNG, I had to use the console and some print calls to understand what is in some of the variables that are provided...

    I noticed the Orbit camera is handled specially; my mod is based on it and has to override it because using a unique name changes the behavior of the camera.
    Kinda beyond me how I can account for that...
     
  8. daniel-w

    daniel-w
    Expand Collapse
    BeamNG Team

    Joined:
    Jan 28, 2017
    Messages:
    282
    Thanks, and no worries. I spend the majority of my time doing this anyway so I might as well help whilst I'm at it :)

    And regarding feedback, I think an example mod that covers all the basics would be great. New modders can then download it and see how everything connects and functions. I learned it all from KissMP, but to be fair, it wasn't too bad. I just had to keep going back to remember how to set up extensions. But I've memorized quite a lot now which is nice.

    And I do have an example mod already, but you obviously know more, and so maybe you or someone else could throw one together for the new modders (or even experienced vehicle modders). There's always something new to learn :)
     
    • 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