Jump to content
RAGE Multiplayer Community

[C#] RAGE.Game.Misc.GetGroundZFor3dCoord always returns 0.0f??


TheOnlyDroid
 Share

Recommended Posts

Posted (edited)

Honestly at this point, I'm beyond ideas; Loading the area collision prior to calling "RAGE.Game.Misc.GetGroundZFor3dCoord", if anyone has any idea's that'd be great.

public static void StartPlayerSwitchToPosition(this Player player, Vector3 pos)
{
    SWITCH_TIME_WAITED = 0;

    RAGE.Game.Invoker.Invoke(0xAAB3200ED59016BC, (int)RAGE.Elements.Player.LocalPlayer.Handle, (int)0, (int)1); // Start Ped/Entity switch

    while (SWITCH_TIME_WAITED < SWITCH_WAIT_TIME)
    {
        SWITCH_TIME_WAITED++;
        RAGE.Game.Invoker.Wait(0);
    }

    RAGE.Game.Streaming.SetFocusArea((float)pos.X, (float)pos.Y, (float)pos.Z, (float)pos.X, (float)pos.Y, (float)pos.Z + 3.8f);

    if (SWITCH_TIME_WAITED >= SWITCH_WAIT_TIME)
    {
        // 797.97(~6)f being the highest point.
        float Z = 797.97f;
        RAGE.Elements.Player.LocalPlayer.Position = new Vector3((float)pos.X, (float)pos.Y, Z);

        RAGE.Game.Streaming.RequestCollisionAtCoord((float)pos.X, (float)pos.Y, (float)pos.Z);
        RAGE.Game.Streaming.RequestAdditionalCollisionAtCoord((float)pos.X, (float)pos.Y, (float)pos.Z);

        bool collision = RAGE.Game.Invoker.Invoke<bool>(RAGE.Game.Natives.HasCollisionLoadedAroundEntity, player.Handle);
                    
        while (!collision)
        {
            collision = RAGE.Game.Invoker.Invoke<bool>(RAGE.Game.Natives.HasCollisionLoadedAroundEntity, player.Handle);
            RAGE.Game.Invoker.Wait(500);
        }

        RAGE.Elements.Player.LocalPlayer.Position = new Vector3((float)pos.X, (float)pos.Y, 797.97f);
        player.FreezePosition(true);

        bool groundZ = RAGE.Game.Misc.GetGroundZFor3dCoord(pos.X, pos.Y, 797.97f, ref Z, false);

        while (!groundZ)
        {
            groundZ = RAGE.Game.Misc.GetGroundZFor3dCoord(pos.X, pos.Y, 797.97f, ref Z, false);
            RAGE.Game.Invoker.Wait(120);
        }

        RAGE.Elements.Player.LocalPlayer.Position = new Vector3((float)pos.X, (float)pos.Y, Z + 3.0f);
        player.FreezePosition(false);

        RAGE.Game.Invoker.Invoke(0xD8295AF639FD9CB8, (int)player.Handle); // End Ped/Entity switch

        SWITCH_TIME_WAITED = 0;
        player.FreezePosition(false);
    }
}

 

Edited by TheOnlyDroid
Link to comment
Share on other sites

  • TheOnlyDroid changed the title to [C#] RAGE.Game.Misc.GetGroundZFor3dCoord always returns 0.0f??
On 6/13/2021 at 2:58 AM, Division said:

I ran into the same lang time ago.

//edit: teleport and wait until map finally streamed

Thanks for the response;

The result is the same even with a pre-position change; Also that's why '0xE9676F61BC0B3321'//'RAGE.Game.Natives.HasCollisionLoadedAroundEntity' is in a while loop.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...