citizenfx / fivem

The source code for the Cfx.re modification frameworks, such as FiveM, RedM and LibertyM, as well as FXServer.
https://cfx.re/
3.48k stars 2.06k forks source link

GetGameplayCamRelativePitch client native not working as expected #2228

Closed Mathu-lmn closed 4 days ago

Mathu-lmn commented 11 months ago

Video

Mathu-lmn commented 11 months ago

https://github.com/citizenfx/fivem/assets/80094438/162de2b8-c3c0-4743-a555-3d026f141fd4

Reuploading the video to allow preview :)

Infinity585 commented 11 months ago

While this is still not working I found using GetGameplayCamRot().x worked to get the cam pitch.

gottfriedleibniz commented 11 months ago

The sequence does look a bit counter-intuitive w/ BaseOrbitPitchOffset, ExtraOrbitPitchOffset (controlled via undocumented natives), LookOverSettings, and whatever else (the entity) having an effect on the 'relative' pitch after the call to SetGameplayCamRelativePitch.

This seems more like a documentation bug. If you truly require absolute-zero, you could, I guess, compensate in the other direction (e.g., +2.046 in your example).

Mathu-lmn commented 11 months ago

Hey, the issue here is I have no way to determine the "offset", depending on where I am on the map, it can either be -2.2, -0.9 or anything in between. But I'll try @Infinity585 's suggestion tho.

gottfriedleibniz commented 7 months ago

Any updates w/ what was suggested? Otherwise, may I close this issue?

Mathu-lmn commented 7 months ago

Hey, I just tested this right now again, but his suggestion didn't work either :/ image

Mathu-lmn commented 7 months ago

image After further investigation, it seems that setting the player's heading to 0.0 "fixes" the getter offset

Mathu-lmn commented 7 months ago

image Okay it doesn't seems related then.... I don't understand those offsets

gottfriedleibniz commented 7 months ago

With third-person cameras it does seem like "relative" here has two different meanings.

  1. SetGameplayCamRelativePitch, as I mentioned above, is a calculation relative to (or constrained by) its orbit configuration.
  2. GetGameplayCamRelativePitch returns the relative pitch between the camera and whatever it is attached too (or following; just a subtraction of two angles).
Mathu-lmn commented 7 months ago

Hmm so it's more a naming convention issue than a game mechanic issue then. How would I get the GameplayCamRelativePitch correctly then ?

gottfriedleibniz commented 7 months ago

Maybe give ClampGameplayCamPitch a shot. See if this helps you achieve the effect you desire.

Mathu-lmn commented 7 months ago

Okay so this actually works but there's a twist. While the ClampGameplayCamPitch native is called each frame, the GetGameplayCamRelativePitch native returns 0.0 successfully, but once the loop ends and the native stops being called each frame the getter returns the weird "random" offset again.

The thing is that I found this issue while developing a feature for a menu, when the player's mouse goes on the top or bottom edge of the screen, the camera moves. I managed to do it for the cam heading correctly, but got this issue for the pitch :/

gottfriedleibniz commented 7 months ago

the getter returns the weird "random" offset again.

For these specific cameras, it is not a setter/getter pair in the traditional sense. The orbit camera has its own restrictions, effects, and limitations (e.g. clipping) that supersede whatever is desired from scripting commands. ClampGameplayCamPitch is just a hack to "force" things to be the way you want.