1. Trouble with the game?
    Try the troubleshooter!

    Dismiss Notice
  2. Issues with the game?
    Check the Known Issues list before reporting!

    Dismiss Notice
  3. Before reporting issues or bugs, please check the up-to-date Bug Reporting Thread for the current version.
    0.36 Bug Reporting thread
    Solutions and more information may already be available.

Teleport to custom coordinates and detect a closed road

Discussion in 'Troubleshooting: Bugs, Questions and Support' started by Neo. 2, Jul 18, 2025.

  1. Neo. 2

    Neo. 2
    Expand Collapse

    Joined:
    Jan 21, 2025
    Messages:
    3
    Hi,

    I have the following code:

    Teleport when not known z axis, +1 meter above terrain (Also, I would appreciate it if someone knew another method to teleport to x, y without knowing the z axis, with a small code block):
    x=-777 y=1700 p=Engine.castRay(vec3(x,y,99999),vec3(x,y,-99999),1,1) if p then be:getPlayerVehicle(0):setPositionNoPhysicsReset(vec3(x,y,p.pt.z+1)) end

    When you know all coordinates:
    be:getPlayerVehicle(0):setPosition(vec3(x, y, z))

    Is it possible to teleport to a closed road after one of the above commands is executed?
     
  2. Neverless

    Neverless
    Expand Collapse

    Joined:
    Sep 18, 2016
    Messages:
    244
    +1 on the Z might work for alot of cars, but definitely not for all. Some will endup with their tires stuck in the ground. the proper way is to use the vehicles bounding box

    Code:
    local function surfaceHeight(pos_vec)
        local z = be:getSurfaceHeightBelow(vec3(pos_vec.x, pos_vec.y, pos_vec.z + 2))
        if z < -1e10 then return end -- "the function returns -1e20 when the raycast fails"
        return z
    end
    
    -- will plant the vehicle with its tires precisely on the ground.
    local function evalTPPosition(pos_vec, vehicle, factor)
        local tar_pos = vec3(
            pos_vec.x,
            pos_vec.y,
            surfaceHeight(pos_vec) or pos_vec.z
        )
       
        local bounding_box = vehicle:getSpawnWorldOOBB()
        local half_extends = bounding_box:getHalfExtents()
        tar_pos.z = tar_pos.z + (half_extends.z / (factor or 4)) -- damaged vehicles have a solid chance to glitch into the ground with this, reduce it to / 3 if necessary
       
        return tar_pos
    end
    
    local function main()
        local vehicle = getPlayerVehicle(0)
        local tar_pos = vec3(0, 0, 0)
        local adjusted_pos = evalTPPosition(tar_pos, vehicle)
        vehicle:setPositionNoPhysicsReset(adjusted_pos)
    end
    
    About the closed road thing, i dont know what you mean
     
    • Like Like 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