Reading a vehicle's rotation from a vehicle controller

Discussion in 'Programming' started by RcCookie, Dec 23, 2022.

  1. RcCookie

    RcCookie
    Expand Collapse

    Joined:
    Feb 24, 2018
    Messages:
    37
    I am new to BeamNG modding, and I'm trying to access some vehicle stats. Because I'm really not good with Lua I just want to write them to a socket and read that from another process.

    I found this relatively old thread about exporting vehicle data to a csv file, and it does still work. I am mainly interested in the vehicle's velocity, position and rotation. Said example however only accesses the position of the vehicle. By trial and error, I have also found obj:getVelocity() and obj:getRotation(). Velocity works fine, but rotation only seems to return the rotation speed, not the absolute rotation, which I would like to have. Also, it is just a scalar, so you can't just sum up the rotation over time because you don't know in which direction the rotation is being performed.

    So my question is, how would you access the vehicles rotation (as quaterion or euler angles)?
     
    • Like Like x 1
  2. angelo234

    angelo234
    Expand Collapse
    Programmer
    BeamNG Team

    Joined:
    Aug 11, 2017
    Messages:
    585
    Here's how you can access the vehicle's rotation (quaternion):
    Code:
    local rot = quat(obj:getRotation())
    local x, y, z, w = rot.x, rot.y, rot.z, rot.w
     
  3. RcCookie

    RcCookie
    Expand Collapse

    Joined:
    Feb 24, 2018
    Messages:
    37
    Ok thanks, that works! Is there also a way to read out the angular velocity?
     
  4. angelo234

    angelo234
    Expand Collapse
    Programmer
    BeamNG Team

    Joined:
    Aug 11, 2017
    Messages:
    585
    Alright here you go and also here's how you get the rotation in euler angles.
    Code:
    local rollAV, pitchAV, yawAV = obj:getRollPitchYawAngularVelocity()
    
    local rot = quat(obj:getRotation()):toEulerYXZ()
    local roll, pitch, yaw = rot.z, rot.y, rot.x
     
    • Like Like x 2
  5. austint30

    austint30
    Expand Collapse

    Joined:
    Aug 7, 2013
    Messages:
    242
    Sorry to reply to an old thread, but I am looking to get the current angular velocity of the vehicle in a camera script so I can apply some effects when the car is spinning quickly.
    obj:getRollPitchYawAngularVelocity() looks promising, but I don't see it used anywhere in the camera scripts. In driver.lua there is a commented out line:
    Code:
    local roll, pitch, yaw = data.veh:getRollPitchYawAngularVelocity()
    Uncommenting causes an error where getRollPitchYawAngularVelocity is nil. Is there a way to access the vehicle's angular velocity in a camera script?
     
  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