Solved Invisible Collision Sensors

Discussion in 'Mod Support' started by EcoNadder77, Oct 10, 2017.

  1. EcoNadder77

    EcoNadder77
    Expand Collapse

    Joined:
    May 29, 2017
    Messages:
    1,150
    Hi guys. Are there any (lua?) commands that would allow me to accomplish the following:
    1. Create an invisible line sticking out the front of the car that's 'n' units in length. This line/sensor will move relative to the car as if it's stuck to the car (see pic below).
    2. Check if any object (vehicle/terrain) is colliding/intersecting with the line.
    3. If there is an intersection, return the distance between the start of the line and the closest intersection point.
    4. Compare the distance to another number.
    5. Do something if a conditional statement is true.
    6. Loop back to #2
    (This red line represents the invisible sensor stuck to the front of the car)
    screenshot_00330.png

    If I'm not mistaken, I believe BeamNG uses something similar to this when you're using the external camera.

    Basically, I want to check if there's something in front of the car, measure the distance between the car and whatever is within a certain distance from it, compare it to a previous distance measurement, and finally trigger something to happen if a certain condition is met.
    Is there a more efficient way to achieve this other than what I previously described?
     
    • Like Like x 2
  2. meywue

    meywue
    Expand Collapse
    BeamNG Team

    Joined:
    Nov 19, 2015
    Messages:
    346
    The thing you're asking for is called Raycasting and unfortunately it's not available in lua (yet).
     
  3. EcoNadder77

    EcoNadder77
    Expand Collapse

    Joined:
    May 29, 2017
    Messages:
    1,150
    Aww, okay. Well, thanks for letting me know.
     
  4. StinchinStein

    StinchinStein
    Expand Collapse

    Joined:
    Jul 16, 2014
    Messages:
    763
    This is in the 0.9 changelog:
    • Exposed new Lua function “castRay”, which can be used in the game engine thread to detect obstacles (will impact performance, use with caution)
    I think the "external" camera lua uses this for raycasting?
    Code:
    be:castRay(self.camPos:toPoint3F(), carPos:toPoint3F())
     
  5. Dummiesman

    Dummiesman
    Expand Collapse

    Joined:
    Sep 17, 2013
    Messages:
    4,696
    Actually it's used on my Avro Arrow
     
  6. sarkarsvt

    sarkarsvt
    Expand Collapse

    Joined:
    Aug 28, 2016
    Messages:
    17
    what for?
     
  7. Dummiesman

    Dummiesman
    Expand Collapse

    Joined:
    Sep 17, 2013
    Messages:
    4,696
    Radar altimeter
     
  8. EcoNadder77

    EcoNadder77
    Expand Collapse

    Joined:
    May 29, 2017
    Messages:
    1,150
    Thanks! Do you mind if I use and modify some of the code from your Radar Altimeter to accomplish my goal in the first post?
     
  9. Diamondback

    Diamondback
    Expand Collapse
    Vehicle Systems Lead
    BeamNG Team

    Joined:
    Apr 8, 2014
    Messages:
    1,966
    Please note that raycasting in GE lua does not work with other vehicles, so you can't detect other cars.
    In addition to that, it's not exposed in vlua, making it slightly cumbersome and not very performant to use.
    I'd recommend a maximum usage frequency of 5 hz, less if possible.
     
    • Like Like x 1
  10. thomatoes50

    thomatoes50
    Expand Collapse
    BeamNG Team

    Joined:
    Jan 31, 2013
    Messages:
    722
    obj:calcCenterOfGravity() return a float3, it's a userdata which means it's a C++ type but you can still use it
    you create an object like this using float3(1, 2, 3)

    here is the extract of the class in lua-doc.zip
     
    • 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