Solved Vehicle collisions (Lua)

Discussion in 'Mod Support' started by Darthbob555, Jan 3, 2017.

  1. Darthbob555

    Darthbob555
    Expand Collapse

    Joined:
    Feb 14, 2016
    Messages:
    290
    Put simply, how can I check whether a collision has occurred between two vehicles?

    I have found this in the campaigns for chapter1 which would seem to do the trick (chapter1_walljump.lua):

    Code:
    local function onObjectCollision(objA, objB)
      -- log('A', logTag, 'onObjectCollision called objA : '..objA..', objB: '..objB)
      local wall = scenetree.findObject(wallInstance)
      if wall then
        local wallID = wall:getID()
        if wallID == objA or wallID == objB then
          playerHitTheWall = true
        end
      end
    end
    However, this never runs when adapted for my code (quick debug message to show current state):

    Code:
    local function onObjectCollision(objA, objB)
        helper.flashUiMessage('Triggering!', 1)
    end
    
    M.onObjectCollision = onObjectCollision
    return M
    Is there something I need to trigger it?

    Thanks for any help.
     
    #1 Darthbob555, Jan 3, 2017
    Last edited: Jan 3, 2017
  2. thomatoes50

    thomatoes50
    Expand Collapse
    BeamNG Team

    Joined:
    Jan 31, 2013
    Messages:
    722
    I don't know why it's not working

    dumb question : Did you declare m?

    Code:
    local M = {}
    
     
  3. Darthbob555

    Darthbob555
    Expand Collapse

    Joined:
    Feb 14, 2016
    Messages:
    290
    Yes. I am not sure why it doesn't work either; I feel like I have done something really stupid here but can't seem to find out what that something is...
     
  4. estama

    estama
    Expand Collapse
    Developer
    BeamNG Team

    Joined:
    Aug 7, 2012
    Messages:
    267
    Check "map.objects" it contains an "objectCollisions" attribute for each object. When a collision happens, you'll see it there.
     
  5. Darthbob555

    Darthbob555
    Expand Collapse

    Joined:
    Feb 14, 2016
    Messages:
    290
    Thank you for your help! How can I access the objectCollisions attribute for the specified vehicle?
     
  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