Set Spotlight to rotate with vehicle moving

Hey guys ‘n’ gals,

I’m working on trying to get a spotlight working on a vehicle (In loose terms), and i’ve hit a block. I’ve got a DrawSpotLight on the vehicle’s position, and tried to have the spotlight rotation/direction offset slightly to the left.

Currently, i’ve tried using ForwardVector, Entity Rotation and GetOffsetFromEntityInWorldCoords. No matter what I try, as soon as I add an offset to the coords returned it sort of works but then if I steer to the right, the light flips to the right side instead.

I’ve attached a gif below…

Essentially, what I want to happen is the spotlight stays aiming at the same position off the left of the vehicle no matter how the vehicle is turned or rotated or steered, it always points out from the left.

Hope someone can help!

The code using forwardvector:

local boneIndex = GetEntityBoneIndexByName(vehicle, extra)
local coords = GetWorldPositionOfEntityBone(vehicle, boneIndex)
local rot = GetEntityForwardVector(vehicle)

DrawSpotLight(coords.x, coords.y - 0.20, coords.z + 0.50, rot.x - 1.0, rot.y, rot.Z, 0, 0, 255, 50.0, 1.0, 1.0, 30.0, 20.0)

As far as i’m aware, lights aren’t actual entities and so can’t be attached sadly

You could use GetEntityMatrix for this purpose

        local forwardVec, rightVec, upVec, pos = GetEntityMatrix(vehicle)
        DrawSpotLight(pos, -rightVec, 0, 0, 255, 50.0, 1.0, 1.0, 30.0, 20.0)

since you want left, you just have to change sign of the rightVec (ie -rightVec)

You’re an absolute star - Do you know what getting an entity’s ‘matrix’ is exactly? Doesn’t matter, I mean it works