Vehicle tracking with a marker

Discussion in 'Programming' started by MarckyMON, Apr 27, 2025 at 11:17 AM.

  1. MarckyMON

    MarckyMON
    Expand Collapse

    Joined:
    Dec 24, 2013
    Messages:
    9
    I am currently working on a script to improve vehicle chasing when the player is in a police vehicle with traffic AI.
    What I have done so far is to slow down time, switch to the suspect vehicle, the switch back to the player vehicle. However, I had to disable this, because it seems make the police AI think that the player vehicle is the suspect vehicle.
    My new idea is to to "track" the suspect vehicle with a large / high enough marker, which is then visible from the player's vehicle, much like how the van in the "Ran in a Van" chase scenario in East Coast, USA is tracked should the player be a certain distance from the target vehicle:

    upload_2025-4-27_11-1-17.png

    I would need to increase the scale / height of these markers, so that it can be seen by the player from a far distance. Could anyone please point me in the direction of how to accomplish this? Thank you!
     
  2. MegaKnight

    MegaKnight
    Expand Collapse

    Joined:
    Sep 12, 2024
    Messages:
    203
    You can use code like this to create a marker and make it follow the player vehicle:

    Code:
    local M = {}
    
    local arrowObj = nil
    
    M.createObject = function()
        if arrowObj then return end
        arrowObj = createObject("TSStatic")
        arrowObj.shapeName = "/art/shapes/arrows/s_arrow_floating.dae"
        arrowObj.scale = Point3F(10, 10, 10) -- scale, in this case very large
        local pos = getPlayerVehicle(0):getPosition() -- insert position of target vehicle, update each frame
        arrowObj:setPosRot(pos.x, pos.y, pos.z + 10, -0, -0.7, 0.7, 0) -- arrow pointing down
        arrowObj.instanceColor = Point4F(1,0,0,1) -- RGBA format
        arrowObj:registerObject('Target_Arrow') -- unique name
    end
    
    M.onPreRender = function()
        if arrowObj then
            local pos = getPlayerVehicle(0):getPosition()
            pos.z = pos.z + 10 -- increase height, so that marker is above vehicle
            arrowObj:setPosition(pos)
        end
    end
    
    
    return M
    You would have to make some adjustments, so the marker follows the correct vehicle.
     
    • Agree Agree x 1
  3. MarckyMON

    MarckyMON
    Expand Collapse

    Joined:
    Dec 24, 2013
    Messages:
    9
    I just gave this a try... you're the GOAT, MegaKnight!

    upload_2025-4-27_13-12-44.png
     
    • 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