SOLVED - Teleporting prop ahead of vehicle

Discussion in 'Programming' started by m8121, Sep 12, 2023.

  1. m8121

    m8121
    Expand Collapse

    Joined:
    Sep 10, 2023
    Messages:
    4
    I'm experimenting with some cannibalized code from this thread.

    Everything seems to be working as I'd like and a prop is teleporting at the front end of the vehicle I'm driving when I enter a lua trigger. The only thing I'd like to modify is to have the prop to appear a small distance ahead of the vehicle. I suck at lua (and math) and I can't seem to figure out how to modify the code. Particularly, I'm not entirely sure what the "getDirectionVector" values are pointing to.

    Here's the code so far:


    Code:
    local function teleportProp(data)
    
        local player = be:getObjectByID(data.subjectID)
        local prop =  be:getObjectByID(00000)
        local position = vec3(player:getPosition())
        local forward = vec3(player:getDirectionVector()):normalized()
    
        position.z = position.z + 3
    
        local coordinate = forward * 2 + position
    
        if data.event == 'enter' then
            prop:setPosition(coordinate)
        end
    
    end
    
    return teleportProp
     
  2. m8121

    m8121
    Expand Collapse

    Joined:
    Sep 10, 2023
    Messages:
    4

    Solved this myself. For anyone wondering you just change the multiplier in this line:

    Code:
    local coordinate = forward * 2 + position
    For some reason, when using this with a lua trigger was giving me wacky results, so I dismissed that as an option.
     
  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