Custom camera modes - possible with 0.5.5

Discussion in 'Programming' started by tdev, Apr 20, 2016.

  1. tdev

    tdev
    Expand Collapse
    Developer
    BeamNG Team

    Joined:
    Aug 3, 2012
    Messages:
    3,031
    I just added support for adding custom camera modes, will be available in the next update (0.5.4.1)

    This is an example of how to integrate your own camera mode into the game. It'll look like this:


    1. Make sure you have Advanced mode activated
    3. Create a new file in folder lua/ge/extensions/core/cameraModes/
    The filename will be the new mode's name. Keep it simple, no spaces or anything special.

    example: topDown.lua :
    Code:
    -- 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
    
    --- This is an example of a custom camera mode :D
    
    local C = {}
    C.__index = C
    
    function C:init()
      --- when this is loaded, the config will be in self alread. I suggest to inspect it:
      -- dump(self)
      self.veloSmoother = newExponentialSmoothing(20, 1)
      self.lastDataPos = vec3()
      self.fov = self.fov or 20
    
      --- this marks it as base mode. It needs to set position, rotation and fov correctly
      self.baseMode = true
      -- add it to the default camera modes?
      self.register = true
    end
    
    function C:update(data)
      -- get the data
      local ref  = vec3(data.veh:getNodePosition(self.refNodes.ref))
      local back = vec3(data.veh:getNodePosition(self.refNodes.back))
    
      -- we need to manually smooth the velocity as its too spiky otherwise which results in bad camera movement
      local velo = self.veloSmoother:get((self.lastDataPos - data.pos):length())
      self.lastDataPos = data.pos
    
      -- figure out the way the vehicle is oriented
      local dir = (ref - back):normalized()
      -- find out the target that we should look on
      local targetPos = data.pos + vec3(dir.x, dir.y, 0) * math.min(50, 70 * velo)
      -- and place the camera above it
      local camPos = targetPos + vec3(0, 0, (velo * 80)  + 50)
      -- then look from camera position to target :)
      local qdir = quatFromDir((targetPos - camPos):normalized())
    
      -- set the data, this needs to happen
      data.res.pos = camPos -- required, vec3()
      data.res.rot = qdir -- required, quat()
      data.res.fov = self.fov -- required
      data.res.targetPos = targetPos -- this is optional
      return true
    end
    
    -- DO NOT CHANGE CLASS IMPLEMENTATION BELOW
    
    return function(...)
      local o = ... or {}
      setmetatable(o, C)
      o:init()
      return o
    end
    
    3. Reload GameEngine Lua to reload the mode on the fly: CTRL+L

    And done, cycle through the modes with 'C' :)

    4. Pack the mod as .zip with the full path inside the zip (see attachment to this post). Then it can be just placed inside the mods/ folder to work :)


    Even if the update is not out yet, wanted to post already so you can have a look :)
     

    Attached Files:

    #1 tdev, Apr 20, 2016
    Last edited: Apr 20, 2016
    • Like Like x 11
  2. Spaceballs the Username

    Spaceballs the Username
    Expand Collapse

    Joined:
    Oct 13, 2015
    Messages:
    568
    Really cool. Correct if I'm wrong, but there is no way to name the camera?
     
  3. tdev

    tdev
    Expand Collapse
    Developer
    BeamNG Team

    Joined:
    Aug 3, 2012
    Messages:
    3,031
    The filename will be its name, should be good enough for now :)
     
    • Like Like x 2
  4. tdev

    tdev
    Expand Collapse
    Developer
    BeamNG Team

    Joined:
    Aug 3, 2012
    Messages:
    3,031
    And released :)

    I hope someone creates cool things with it now
     
    • Like Like x 1
  5. Destroyer247_52

    Destroyer247_52
    Expand Collapse

    Joined:
    Mar 9, 2015
    Messages:
    188
    How can you determine the location of the camera in the game?
     
    • Like Like x 1
  6. GameNoobTV

    GameNoobTV
    Expand Collapse

    Joined:
    Aug 28, 2015
    Messages:
    413
    Someone needs to create a panning (cinematic) camera if its possible.
     
    • Like Like x 2
  7. SlamSmith

    SlamSmith
    Expand Collapse

    Joined:
    Jul 3, 2015
    Messages:
    1
    This is really great, should allow for some great shots! However, how do we define the cameras position in relation to the vehicle?
     
  8. tdev

    tdev
    Expand Collapse
    Developer
    BeamNG Team

    Joined:
    Aug 3, 2012
    Messages:
    3,031
    See the new relative camera mode :)
     
    • Like Like x 1
  9. tdev

    tdev
    Expand Collapse
    Developer
    BeamNG Team

    Joined:
    Aug 3, 2012
    Messages:
    3,031
    No new camera modes yet? :(
     
    • Like Like x 3
  10. Funky7Monkey

    Funky7Monkey
    Expand Collapse

    Joined:
    Oct 12, 2014
    Messages:
    977
    Just for you ;)
     
    • Like Like x 2
  11. James Smith

    James Smith
    Expand Collapse

    Joined:
    Mar 16, 2016
    Messages:
    265
    That is pretty cool, it looks very similar to the camera in RoR.
     
  12. Funky7Monkey

    Funky7Monkey
    Expand Collapse

    Joined:
    Oct 12, 2014
    Messages:
    977
    When are the functions C:reset and C:reload called? Also, where does the data for C:setFOV and C:setOffset come from (what does the player do to change these)?
     
  13. tdev

    tdev
    Expand Collapse
    Developer
    BeamNG Team

    Joined:
    Aug 3, 2012
    Messages:
    3,031
    reset - whenever the camera is resetted
    reloaded - whenever the module is being reloaded completely - so when the vehicle is reloaded.
    setFov, setOffset: from the jbeam: fov and offset of the camera's n/b section
     
    • Like Like x 2
  14. TeenWolf896

    TeenWolf896
    Expand Collapse

    Joined:
    Oct 13, 2014
    Messages:
    95
    Do any of you happen to know how to have the vehicle camera spawn in at Default Orbit position after each respawn? It stopped automatically resetting for me after I respawn a vehicle, and it becomes annoying having to always manually reset the camera after moving it around before the vehicle was reset. I've searched all over Google and none of the Keypad Numbers work for me, they just serve as another driving pad.

    For example, if I set it manually after driving for a bit and keeping it facing the default direction, If I we're to respawn my vehicle, the camera would be facing the front. Basically the camera flips 180 degrees after each respawn, based on the previous camera position before respawning.

    *No I have not changed any of my controls, they are default.
     
  15. Bernd

    Bernd
    Expand Collapse

    Joined:
    Dec 27, 2015
    Messages:
    1,387
    Pressing the "Num" button in the upper three button row of the keyboard should fix that, you've probaby hit it accidentally and turned the number keys of that way :).
     
  16. Funky7Monkey

    Funky7Monkey
    Expand Collapse

    Joined:
    Oct 12, 2014
    Messages:
    977
    This doesn't seem to be working. For clarification, this function should be called when the vehicle is reset (pressing "r") or reloaded ("ctrl+r")?
     
  17. TeenWolf896

    TeenWolf896
    Expand Collapse

    Joined:
    Oct 13, 2014
    Messages:
    95
    Which number do I press to reset the camera? I'm looking for a way to have it automatically reset after each respawn anyways...
     
  18. Bernd

    Bernd
    Expand Collapse

    Joined:
    Dec 27, 2015
    Messages:
    1,387
    Numpad 5, but as I've said, you might have deactivated it.
     
  19. TeenWolf896

    TeenWolf896
    Expand Collapse

    Joined:
    Oct 13, 2014
    Messages:
    95
    Yeah "Num" doesn't change having the numbers act as a seperate way to drive a vehicle, nothing new.
     
  20. Bernd

    Bernd
    Expand Collapse

    Joined:
    Dec 27, 2015
    Messages:
    1,387
    That's unfortunate to hear :/.
     
  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