So, we can use some data from the engine in our vehicle lua code, but I'm struggling to get some data I need. It appears the data is available to the UI apps through a stream, but I can't access it with the vehicle lua? Is there a way for the vehicle lua to access the streamed data? (ideally without modifying any of the core files) Specifically, i'm after the vehicle roll (sensors.roll) but I imagine any advice will be global.
What do you want to achieve? We can help you maybe if we know the whole thing of what you want to get working
That's classified Basically, I'm trying to create a motorcycle. Or rather, I've created a motorcycle, and I want it to stay upright. If I can read the vehicle roll and speed, I can calculate a required steering input to tilt the vehicle towards the target roll (set by steering_input) but I can't seem to read roll at the moment. I can already get it sort-of working at very high speeds by having the steering hydros acting backwards and having a low spring rate, but this method of control requires high gyroscopic forces, so isn't ideal. Dummiesman, thanks, hadn't thought of looking there. I'll give that a go this evening - - - Updated - - - Ok, here's where you can laugh at my noobiness... guistreams.lua contains the following segment: Code: if M.sensors>0 then local dirVector = obj:getDirectionVector() local dirVectorUp = obj:getDirectionVectorUp() local position = obj:getPosition() sensorvalues = { gx = sensors.gx, gy = sensors.gy, gz = sensors.gz, gx2 = sensors.gx2, gy2 = sensors.gy2, gz2 = sensors.gz2, gxMax = sensors.gxMax, gxMin = sensors.gxMin, gyMax = sensors.gyMax, gyMin = sensors.gyMin, gzMax = sensors.gzMax, gzMin = sensors.gzMin, ffb = hydros.lastFFBforce, ffb2 = hydros.lastFFBforce2, position = { x = position.x, y = position.y, z = position.z }, roll = dirVectorUp.x * -dirVector.y + dirVectorUp.y * dirVector.x, pitch = dirVector.z, yaw = obj:getDirection(), gravity = Settings.gravity } gui.send('sensors' , sensorvalues ) end and I've stuck the following in my vehicle lua file: Code: local function updateGFX(dt) local dirVector = obj:getDirectionVector() local dirVectorUp = obj:getDirectionVectorUp() --local position = obj:getPosition() --local roll = dirVectorUp.x * -dirVector.y + dirVectorUp.y * dirVector.x, --local pitch = dirVector.z, --local yaw = obj:getDirection(), if electrics.values['wheelspeed'] < speedThreshold then electrics.values['leansteer'] = 0 else electrics.values['leansteer'] = (Kp * roll) / electrics.values['wheelspeed'] end end The above runs fine (but does nothing), but as soon as I uncomment the 'local roll' line, the game freezes and the console fills up with the following error message which confuses me: Code: libbeamng.object|[string "lua/vehicle/main.lua"]:25: attempt to index global value "drivetrain" (a nil value) I imagine I'm committing some lua faux pas...
Remove the comma at the end of the "local roll" line. ??? Profit Idk, works for me . Remove the comma too from the yaw and pitch lines if they're going to be used. They were needed originally as the lines were in some sort of array or something, but now they are not needed. Report here if it still doesn't work. Apart from that, you seem to be going on the right track.
doh, getting confused with jbeam and lua... Awesome, thank you very much, that bit is now working. Give me a few days to write a better algorithm and tune the variables are I should (hopefully) have something basic to release!
I've noticed that this kind of error Code: libbeamng.object|[string "lua/vehicle/main.lua"]:25: attempt to index global value "drivetrain" (a nil value) often simply means: Syntax Error! Make sure to check your syntax if you encounter it again.