Car collision

I’m using SetEntityNoCollisionEntity for collision. It is working perfectly.

However, when car collision happens, camera angle changes completely.

How to prevent that camera angle change when car collision happens ?

Thanks!

Don’t use SetEntityNoCollisionEntity, but instead use SetNetworkVehicleAsGhost - Natives @ Cfx.re Docs.

SetNetworkVehicleAsGhost didnt work for me.

Mark the other players’ vehicles as ghost. This is exactly what is used for GTAO’s non-contact races.

But it will also go through NPCS and other non racers ( live players ) cars right ?

What I want is, only racers cars should go through each others.

Also I tried using on client side,

SetNetworkVehicleAsGhost(VehToNet(car), true)

Tried without VehToNet(car)

SetNetworkVehicleAsGhost(car, true)

But didn’t work in both cases. Any idea why ?

Use SetLocalPlayerAsGhost - Natives @ Cfx.re Docs instead, you can also use SetGhostedEntityAlpha - Natives @ Cfx.re Docs to set the alpha value of other players.

1 Like

I tried this code. In this code I tried to mark every vehicle as a ghost which is nearby me. But didn’t work. Can you help me with this? Calling this event once client side.

RegisterNetEvent('hp-coll:client:MakePlayerReady')
AddEventHandler('hp-coll:client:MakePlayerReady', function(type)

    SetGhostedEntityAlpha(255)

    veh = GetVehiclePedIsIn(PlayerPedId())
    local vehList = GetGamePool('CVehicle')
    SetNetworkVehicleAsGhost(veh, true)

    for k,v in pairs(vehList) do
        SetNetworkVehicleAsGhost(v, true)
        
    end

end)

Am I doing something wrong here?

Edit: Does it work on NPC vehicles? Because I tried to ghost them too. Should I test with real players?

That native doesn’t seem to work (at least in a 2545/OneSync environment)

The following should work for you:

SetGhostedEntityAlpha(254) -- 254 because 255 doesn't exist according to the native doc
RegisterNetEvent('hp-coll:client:MakePlayerReady', function(type)
    SetLocalPlayerAsGhost(true)
end)
 
RegisterNetEvent('hp-coll:client:MakePlayerUnReady', function(type)
    SetLocalPlayerAsGhost(false)
end)

You won’t have any collision with other players (including Peds)

2 Likes

This sets a Player as Ghost, will it set the vehicle as a ghost ?

The entire purpose of doing is this so that Racer’s car don’t get bumped in each other!

Yes, when your player is a ghost it also sets your vehicle as a ghost to other players.

1 Like

It ghosts all the players.

So what is the solution ? What is the script to solve this problem?