View RSS Feed

tdev

First Vehicle Lua Mod

Rate this Entry
by
tdev
, 01-16-2014 at 03:26 PM (8356 Views)
So, since we added a Lua modding/hooking API into our latest testing version, we enable the mod creators to extend the Lua functionality that we ship by default.

As example, we want to have speed-sensitive dynamic steering on certain hydros so that the steering of certain wheels will reduce the faster you get.
Let me walk you through how to get it working. (once we release the update to the public for sure)

1. Change your hydros so that they are not driven by the steering anymore: I.e. change

["x43l","x44l", {"factor": 0.20,"steeringWheelLock":700,"lockDegrees":35}],

to
["x43l","x44l", {"factor": 0.20,"steeringWheelLock":700,"lockDegrees":35, "inputSource":"steering_speeddependant"}],


2. add a new folder to your vehicle folder, called 'lua'. The game will load any .lua files in there.

3. write the lua extension (lua/rearSteering.lua):

-- 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 maxSpeed = 10 -- in meters per second

local function init()
if v.data.dynamicSteering.maxSpeed ~= nil and type(v.data.dynamicSteering.maxSpeed) == 'number' then
maxSpeed = v.data.dynamicSteering.maxSpeed
end
end

local function updateGFX(dt)
electrics.values['steering_speeddependant'] = electrics.values['steering_input'] * math.max(0, (maxSpeed - math.abs(electrics.values['wheelspeed'])) / maxSpeed)
end

-- public interface
M.updateGFX = updateGFX
M.init = init
return M

The updateGFX, init and reset functions are called automatically by the game.

To make it easier for the vehicle creator, one can add the gimmick to read out options by adding them to the .jbeam instead of hardcoding them into the lua. The above mod uses this new section in the jbeam file:


"dynamicSteering":
{
"maxSpeed":10,
}


And done, this vehicle has now very nice, very custom speed-sensitive steering

Updated 01-16-2014 at 10:16 PM by tdev

Categories
Company Blog

Comments

  1. saetta5's Avatar
    Good work guys. I can't wait for the update
  2. aka_ambush's Avatar
    so do the default cars have that done already in the update?
  3. AirSKiller's Avatar
    I think dynamic steering may be what this game needs to finally put an end to the critics that argue that the cars feel unrealistic.

    Take Assetto Corsa for example, awesome driving sim, the cars feel awesome to drive and you feel in control, now go to controller settings and put speed sensitivity (basically dynamic steering) off and increase the steering speed to look like BeamNG... Yeah, now the cars drive awful and they are as easy to steer as a cat is to teach talking...

    In my opinion dynamic steering and lower steering speed is really important in BeamNG, in a real car you don't turn your wheel 360ยบ in half a second while doing 100 mph, and steering slowly, even with a controller, is somewhat hard.

    Edit: tdev, you might want to categorize this Dev Blog to
    ' Company Blog ' all the other ones (except one other of yours which is also ' Uncategorized ') is in that category.
    Updated 01-16-2014 at 05:54 PM by AirSKiller
  4. Incognito's Avatar
    Documentation will be?
  5. tdev's Avatar
    Quote Originally Posted by AirSKiller
    Edit: tdev, you might want to categorize this Dev Blog to' Company Blog ' all the other ones (except one other of yours which is also ' Uncategorized ') is in that category.
    thanks
  6. tdev's Avatar
    Quote Originally Posted by Incognito
    Documentation will be?
    yes, hopefully
  7. raiderfan's Avatar
    Can't wait looking forward to the new things in the race update.
  8. Tmanning47's Avatar
    Speed steering sensitivity is horrible for wheel users.
  9. gabester's Avatar
    Quote Originally Posted by Tmanning47
    Speed steering sensitivity is horrible for wheel users.
    As far as I know this code was written for an 8x8 for the rear wheels to have adaptive steering, so it wouldn't affect the front wheels or wheel users.
  10. SHOme1289's Avatar
    Sounds good for keyboard users, but will there be an in game option to turn the feature on or off, or will it just be a matter of re-writing a line or two of code? Biggest problem is minute steering adjustments at medium to high speed on keyboard, and it jerks the wheel and causes you to lose traction....as Im sure everyone knows already lol great progress tho.
  11. gabester's Avatar
    Quote Originally Posted by SHOme1289
    Sounds good for keyboard users, but will there be an in game option to turn the feature on or off, or will it just be a matter of re-writing a line or two of code? Biggest problem is minute steering adjustments at medium to high speed on keyboard, and it jerks the wheel and causes you to lose traction....as Im sure everyone knows already lol great progress tho.
    In case it was not clear, this vehicle-specific Lua is for rear wheel steering. It does not affect the steering angle of the front wheels at all.
  12. Kamil_'s Avatar
    Woooo! Finnally I can add lua to vehicles (without modifying core files )
  13. GregBlast's Avatar
    That's really gonna be useful. I've got a question though. Wil it be possible to define general modules by putting them into the "common" vehicle folder ? I say that because a module like yours could potentially be used by all vehicles. It's a static code that takes dynamic input. If the vehicle doesn't have "dynamicSteering" in its jbeam then the code just won't do anything. So it's fine for vehicles that shouldn't use it. But would make it easier for other vehicles as the module would already exist. And if not we could end up with plenty of duplicates.

    The only problem I see in this is that we are a community and multiple people could want to make a "dynamic steering" module differently. So in "common" they would overwrite each other. But in that case we could imagine having sub-folders by user or something. Or a variable in the module could define the user whose it belongs to and it would be loaded separately in the global environment.

    Or maybe I'm thinking too generic and "dynamicSteering" will be an available value in a predefined list and will always exist ?
    Updated 02-02-2014 at 02:43 PM by GregBlast

Trackbacks

Total Trackbacks 0
Trackback URL: