Check if there's a vehicle near this position?

Evening all,

So I’m attempting to check whether or not there’s a vehicle within radius of a given position, however GetClosestVehicle doesn’t seem to be aiding me in this as it always returns that there’s no vehicle there.

I’ve read on a few threads that this problem seems to persist, however all solutions point to using RayCasting, which while helpful doesn’t really help me in my case ( I think ) as I’m looking to simply check if there’s a vehicle near a position, rather than checking if the player is looking at a vehicle ( I assume they use this for the likes of removing vehicles ).

Anyway, hopefully someone might have a way I can get around this issue? Thanks all :slight_smile:

Are you even using it correctly?

GetClosestVehicle(x, y, z, radius, modelHash, flags)

Yes, believe it or not, I have the capability of using arguments.

Might I ask what unit they use in regards to radius? Are we talking meters? I read on another thread something in regards to “units”, however I’m unsure how that would translate to this.

GetClosestVehicle is broken AFAIK. You could always try using a raycast to check a certain distance behind the vehicle instead.

I think somewhat meter… but not really… also it might work but only for a few cars if you put the right flag.

That’s unfortunate,

Well no matter, I’m sure I’ll find a work around eventually, thanks regardless WolfKnight :slight_smile:

Edit: See I mentioned RayCasting beforehand, but I’m wondering how I could actually check the area before hand, I mean as far as the scripts concerned, there’s no vehicle there.

Ah yes I read somewhere about all the different flags, how it doesn’t seem to pick up things like planes and boats or something of the sort.

Check my delete vehicle script, the ray cast I used checked a certain number of units in front of the player and only returned what was between the player and the end point.

The problem there is that I’m not really looking for vehicles in front of the player, but rather checking if there’s a vehicle within a given radius of a specified position.

In this case, we can disregard the player entirely

Do you solve your problem ? I have the same problem :confused: I need radius

Found a working example guys - this served as my north star:

Judging by the working example in github, it looks like it works based on proximity to the CENTER of the vehicle! Sweet!