Calculate point beside (perpendicular) to vehicle

Discussion in 'Programming' started by Riccarr, Aug 2, 2024.

  1. Riccarr

    Riccarr
    Expand Collapse

    Joined:
    Jul 28, 2024
    Messages:
    18
    Hello ... as the title says, I want to calc a point perpendicular to vehicle.

    I have this code to calculate a point x units forward of vehicle ...

    local position = vec3(veh:getPosition())
    local forward = vec3(veh:getDirectionVector())
    local coordinate = forward * x + position

    But how to calc a point x units beside the vehicle?

    Much appreciate any help. Cheers!
     
  2. Occam's Razer

    Occam's Razer
    Expand Collapse

    Joined:
    Aug 7, 2013
    Messages:
    1,242
    IIRC, there's similar code to determine the vehicle's up vector. Combine the forward vector and the up vector with a dot product, and that should give you a position next to the vehicle.

    Edit: sorry, cross product. SineMatic has it right
     
    #2 Occam's Razer, Aug 2, 2024
    Last edited: Aug 2, 2024
    • Like Like x 1
  3. SineMatic

    SineMatic
    Expand Collapse

    Joined:
    Nov 17, 2022
    Messages:
    60
    From drivingDynamics\sensors\vehicleData.lua:

    Code:
    vectorRight = vectorForward:cross(vectorUp)
     
    • Like Like x 2
  4. Riccarr

    Riccarr
    Expand Collapse

    Joined:
    Jul 28, 2024
    Messages:
    18
    Hey guys, thanks. That help me figure out how to calculate position left or right of vehicle position.

    local vecPosition = vec3(veh:getPosition())
    local vecForward = vec3(veh:getDirectionVector())
    local vecUp = vec3(veh:getDirectionVectorUp())
    local vecRight = vecForward:cross(vecUp)​

    local lr = (math.random() * 1.2) - 0.6 -- generate a random left/right offset
    local target = vecForward * fillSpot + vecPosition -- get inital location on trailer center (which doesn't appear to be centered left/right)
    target = vecRight * -0.5 + target --tweak position left
    target = vecRight * lr + target -- apply random offset left or right (positive or negative value)​
     
    • Agree Agree x 1
  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