Hello.
I’ve been doing a project that requires me to raycast where I’m aiming.
The raycast works fine, and I’ve been using the gameplay cam as my way of doing this.
It’s very unprecise, and does not lead to the result I want.
Is there some way to get the coords of the crosshair, so that I can cast my ray starting from that?
Thank you.
local function GetEntInFrontOfPlayer(Distance, Ped)
local Ent = nil
local CoA = GetEntityCoords(Ped, 1)
local CoB = GetOffsetFromEntityInWorldCoords(Ped, 0.0, Distance, 0.0)
local RayHandle = CastRayPointToPoint(CoA.x, CoA.y, CoA.z, CoB.x, CoB.y, CoB.z, 10, MyPed(), 0)
local A,B,C,D,Ent = GetRaycastResult(RayHandle)
return Ent
end
Hi this casts a ray from the front of an entity at distance X. Works on moving vehicles.
Thanks, but that’s kind of what I had to start with. This does not focus on where you’re aiming with you weapon, and your crosshairs position though.
If I just use:
local bool, entity = GetEntityPlayerIsFreeAimingAt(PlayerId())
And print the resulting entity in the console, I get everything showing up just fine. It finds the detected entities, and prints out their ID.
It does not work however, later in the script - where I try to get the speed of said Entity, the model and etc.
That only works using a raycast, which confuses me.
Had a bit of an issue, and now speed works perfectly for every vehicle.
However - Model, and platetext do not work unless the vehicle aimed at is spawned by me.
What could that be?
It’s picking up the Peds Entity. You can use the natives to check if the entity is a ped, and then get their vehicle id and you will be and to get the plate and car model