How do I check if the camera is underwater?

Discussion in 'Programming' started by DaddelZeit, Sep 30, 2021.

  1. DaddelZeit

    DaddelZeit
    Expand Collapse

    Joined:
    Jul 17, 2019
    Messages:
    3,085
    I know it's possible, as the game has underwater ambient sounds.
    However, even after searching every file (yes, even in the game engine) I have not been able to figure it out.
    The only finding was in lua/ge/extensions/core/sounds.lua:

    Code:
          local camObj = getCamera()
          camObj = (camObj and Sim.upcast(camObj)) or camObj
          globalParams:setParameterValue("g_CamFree", commands.isFreeCamera() and 1 or 0)
          globalParams:setParameterValue("g_CamUnderwater", (camObj and camObj:isCameraUnderwater() and 1) or 0)
    It seems to be using a isCameraUnderwater() function, however I am unable to call it.
    This command:
    Code:
          obj:queueGameEngineLua("local camObj = getCamera() if (camObj and camObj:isCameraUnderwater() and 1) then camIsUnderwater = true else camIsUnderwater = false end")
    Results in:
    upload_2021-9-30_14-17-57.png

    Oh, and I have not found the function isCameraUnderwater() anywhere other than in sounds.lua
     
    #1 DaddelZeit, Sep 30, 2021
    Last edited: Sep 30, 2021
  2. S.Ali.M

    S.Ali.M
    Expand Collapse

    Joined:
    Jan 12, 2021
    Messages:
    1,080
    Idk maybe use this code
    Code:
    camObj = (camObj and Sim.upcast(camObj)) or camObj
    This code has been used in the sounds.lua but not in yours, so probably it's the problem



    Also, why you used obj:queueGameEngineLua in your code?
     
  3. DaddelZeit

    DaddelZeit
    Expand Collapse

    Joined:
    Jul 17, 2019
    Messages:
    3,085
    That did fix it, thanks!
    To execute the code in the game engine, as I cannot access the core stuff from the vehicle lua.
    --- Post updated ---
    Alright, so I got it to work!
    https://cdn.discordapp.com/attachme...856420560936/BeamNG_2021.09.30-19.52_Trim.mp4
    The command to check if the camera is underwater is:
    Code:
    obj:queueGameEngineLua('local camObj = getCamera()   camObj = (camObj and Sim.upcast(camObj)) or camObj   if (camObj and camObj:isCameraUnderwater() and 1) then be:getPlayerVehicle(0):queueLuaCommand("camIsUnderwater = true") else be:getPlayerVehicle(0):queueLuaCommand("camIsUnderwater = false") end')
    camIsUnderwater is set as a global for use in the vehicle.
     
    #3 DaddelZeit, Sep 30, 2021
    Last edited: Oct 3, 2021
    • Like Like x 2
  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