[C#] Not the same result using GetOffsetPosition and the native call



I wanted to teleport my character a bit forward by pressing a key and I noticed these two functions doesn’t return the same result:

LocalPlayer.Character.Position = LocalPlayer.Character.GetOffsetPosition(new Vector3(0.0f, 1.5f, 0.0f));
LocalPlayer.Character.Position = Function.Call<Vector3>(Hash.GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS, LocalPlayer.Character, 0.0f, 1.5f, 0.0f);

When using GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS, the input vector is Vector3(right/left, front/back, up/down).
But using Entity.GetOffsetPosition, it seems to be Vector3(right/left, up/down, front/back).

Y and Z are switched.

Why does it behave like this?

I use the latest FiveM version (I had an update tonight) and also tried the latest CitizenFX version.


In your Function.Call, you are not calling the ped properly. You need to do Character.Handle, which gets the actual ped ID.

I tested the following code, and as you can see from the screenshot, everything is exactly the same. (Didn’t realize it was the .Handle until after)

Vector3 A = Game.PlayerPed.GetOffsetPosition(new Vector3(0f, 1.5f, 0f));
Vector3 B = API.GetOffsetFromEntityInWorldCoords(Game.PlayerPed.Handle, 0f, 1.5f, 0f);
Vector3 C = Function.Call<Vector3>(Hash.GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS, Game.PlayerPed.Handle, 0.0f, 1.5f, 0.0f);

Vector3 A2 = Game.Player.Character.GetOffsetPosition(new Vector3(0f, 1.5f, 0f));
Vector3 B2 = API.GetOffsetFromEntityInWorldCoords(Game.Player.Character.Handle, 0f, 1.5f, 0f);
Vector3 C2 = Function.Call<Vector3>(Hash.GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS, Game.Player.Character.Handle, 0.0f, 1.5f, 0.0f);

(#: is current position)

PS. Why not just use the API.?


But the Function.Call returned the correct value.
The wrong value was returned by LocalPlayer.Character.GetOffsetPosition(new Vector3(0.0f, 1.5f, 0.0f));

I wanted to see if there was a difference with between this result and the one from the native function, that’s why I called it using Function.Call (apart from calling GetOffsetPosition oc).

The odd thing is, I’m unable to reproduce the problem using the same code as before, I will see if it happens again…

I’m used to ScriptHookVDotNet2, so I didn’t think about using API :wink:

Thanks a lot for your testing btw, I will reopen a thread if I encounter this issue again and I will test it using these 4 different ways.