Unsolved Creating an oscillating light behavior

Discussion in 'Mod Support' started by GravelRoadCop, Feb 23, 2025.

  1. GravelRoadCop

    GravelRoadCop
    Expand Collapse

    Joined:
    Apr 15, 2016
    Messages:
    2
    I'm trying to modify the beaconSpin.lua function in BeamNG to create an oscillating (side-to-side) motion for a beacon light, instead of having it spin continuously in one direction (360 spin)

    What I’ve Tried:
    1. I created a new function called beaconOscillate based on the existing beaconSpin code.
    2. Instead of a full 360° rotation, I attempted to limit it to -30° to 30° using math.sin() in the script.
    3. I modified the JBeam props section to use this new function.
    This is what it looks like. Keep in mind I am new to this, so it's not perfect.

    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
    
    local M = {}
    M.type = "auxiliary"
    
    local oscillationTime = 0
    local beaconSpeed = 0
    local electricsName = nil
    
    local function updateGFX(dt)
      if electrics.values.lightbar > 0 then
        oscillationTime = oscillationTime + dt * beaconSpeed
        local angle = 30 * math.sin(oscillationTime) -- Should oscillate between -30° and 30°
    
        electrics.values[electricsName] = angle -- Apply oscillation angle
      else
        electrics.values[electricsName] = 0
        oscillationTime = 0
      end
    end
    
    local function init(jbeamData)
      beaconSpeed = jbeamData.spinSpeed or 4 -- Adjusted speed for oscillation
      electricsName = jbeamData.electricsName or "beaconOscillate"
      electrics.values[electricsName] = 1
    end
    
    M.init = init
    M.updateGFX = updateGFX
    
    return M

    • Am I missing something in the electrics system to trigger movement?

    • Is there a better way to achieve an oscillating motion within the existing BeamNG prop system? I would like to have a beacon lightbar that oscilates left to right rather than full spin.

    Here's an example video of what I would like to accomplish:

     
  2. Sopze

    Sopze
    Expand Collapse

    Joined:
    Nov 30, 2017
    Messages:
    46
    seems like you changed the electrics name from beaconSpin to beaconOscillate

    sirens props use beaconSpin's value for its rotation, if you change the name you would need to create custom sirens that use your beaconOscillate value... for each car that has sirens
     
  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