While looking through the `orbit.lua` camera code*, I came across an `update(data)` function which seems to recieve some `data` variable from streams/sensors, and constantly repeats executing the function body. function C:update(data) I want to make a camera mod which recieves this same `data`, and modifies the camera position constantly, e.g to increase camera distance at high speeds. However, I'm not sure how to "call" this `data` from, and how to make my function run at all/repeat constantly. Currently it does not run at all. The BeamNG documentation is nonexistent, and the wiki's Lua Reference is still severely lacking and is bugged out for me. If anyone could point me in the right direction for good documentation, or how to go about solving my problem, it would be a big help. *This camera code is located at `\lua\ge\extensions\core\cameraModes\orbit.lua`.
As far as I know the C: means that it's handled by the game engine so I'm not sure if something like this is even possible, could be wrong though
According to this official Lua guide https://www.lua.org/pil/5.html, the C: is just a way to declare an object-oriented function, i.e C:foo(x) is equal to C.foo(C, x)
Hey! So for custom camera modes, this thread from v0.5.5 (!!!) describes how to set up a camera mod: https://beamng.com/threads/custom-camera-modes-possible-with-0-5-5.24111/ . Code: function C:update(data) This gets called from and receives data from lua/ge/extensions/core/camera.lua, and it gets called every frame automatically if you set it up correctly. The info in the thread is mostly compatible, except you need to add an additional function: Code: function C:setRefNodes(centerNodeID, leftNodeID, backNodeID) I attached an updated example that you can use or copy. By the way, while I'm here, this is unrelated to the camera code, but it is the generic way to set up a function in a Lua module so it can get repeated every frame: Code: local M = {} local function onUpdate(dtReal, dtSim) -- code goes here end M.onUpdate = onUpdate return M
Thank you so much for all of this info! Do you have any other threads/ documentation which would be useful or relevant? My goal is modifying the currently selected camera's properties to increase CameraDistance or FOV, not to create an entirely new camera mode. Is this possible to do?
Yup, it should be possible. Although, the code in orbit.lua gets pretty complicated; even I need to study it for a while to figure things out. The code around line 374 seems to be where the speed-dependent distance and fov get set. See if you can get some changes working there; I'll definitely try to crunch some numbers when I have time.
I've successfully modified the code of orbit.lua to add new functionality before. But is it possible to modify or add extra functionality to the orbit camera's behavior without changing or replacing the original orbit.lua file? If so, then the camera mod I am making can be uploaded to the repository. Else, it will be a hassle for users to find and replace the vanilla orbit.lua with a modified version from some random source
Ah, let's see... I think you can simply create a copy of orbit.lua, give it a unique name, make sure that it is in lua/ge/extensions/core/cameraModes folder, and it will automatically be usable in the game (i.e. switchable by pressing C or the main number keys). And then you can pack the mod this way.
This would be quite redundant though. What about "injecting" extra code/functional into the update function of orbit.lua from the mod, so that an entirely new camera mode does not need to be created? Is that possible? Perhaps this would mean "implementing" a function from a module and over-writing it from a mod.
So far looks like my only way is to create a new camera mode and copy orbit.lua's code. My main concerns of this way are: I will have to maintain the custom camera alongside orbit.lua, and merge/fix any conflicts or changes from the orbit.lua. Leads to redundant, duplicated code (two orbit camera versions). A modular way would be much more cleaner and programmatic. Might have to manually enable this camera mode in each and every vehicle's jbeam, which is too time consuming Will this camera mode be available in BeamNG settings? Edit:Seems like the core_camera module is my friend here. Maybe I can use that to modify the camera settings. What does "res" stand for in camera.lua?
How can I create a function which both recieves the camera data AND gets repeated every frame, but is NOT in the cameraModes folder NOR gets called by core_camera (or) camera.lua? And where do scripts in the /lua/ge/extensions/<modname subfolder>/ get called from?