Try / OpenGothic

Reimplementation of Gothic 2 Notr
MIT License
1.15k stars 80 forks source link

Camera lurches while following player #468

Closed mundifex closed 1 year ago

mundifex commented 1 year ago

In OpenGothic, when the player moves forward the camera appears to rubber band at steady intervals, pausing momentarily before catching up to the player and then settling and repeating the process all over again. This lurching movement is best observed in the game itself, but here's a video depicting the lurching (pay close attention to the distant tree on the left and the fences near the end of the video):

https://github.com/Try/OpenGothic/assets/1395806/dc762fc8-c4ab-4da2-82d2-4070b444d13c

In the GOG.com version of Gothic 2, the camera follows the player smoothly, with no detectable lurching:

https://github.com/Try/OpenGothic/assets/1395806/e22ced48-dc3e-4f0d-b2e7-6e8ab49bfec7

Both videos were captured using OBS in Display Capture mode. Windows 10 64-bit.

Try commented 1 year ago

Hi, @mundifex !

This lurching movement is best observed

Can really see anything, probably my perception got blurry, after looking into this camera for years :) If you can point me out at exact time codes, that will help. toggle camdebug marvin command is also helpful to see how exactly camera follows

In general assumption is that camera has to follow root-bone of npc, what might cause issues, since this bone is animated.

Also, slightly related: 57241ed3 - changes animation blending, so camera tilt at picking items will be better.

Nindaleth commented 1 year ago

If you can point me out at exact time codes

The camera (so actually the character) movement within each run animation loop is not linear in the distance traveled each frame, unfortunately we'd have to tag specific video frames to pinpoint it. I can describe it as the forward movement speeding up temporarily for a short moment - every time the left foot lands and then pushes off the ground again. There might be a slight slowdown taking place sometimes else during the loop, but all I can perceive is that speedup.

mundifex commented 1 year ago

Here's a better video demonstrating the lurching: https://www.mediafire.com/file/tg5oh9p7p6phsxa/blacksmith_sign_lurching.mp4/file

Watch the blacksmith sign as the player ascends the street (or the road sign to the right). The movement of the camera is not smooth -- it lurches cyclically after the player has reached their cruising speed. To my eyes, it seems to lurch once every second.

I have my game capped at 144 FPS but this still occurs even with uncapped frame rate.

mundifex commented 1 year ago

Here's another attempt to capture the lurching with some text overlaid to indicate where I'm seeing it occur. The text appears a split second before the lurch occurs.

https://github.com/Try/OpenGothic/assets/1395806/93d0cb9b-0384-4c79-9e3f-118dd06ae745

Try commented 1 year ago

I've pushed https://github.com/Try/OpenGothic/tree/camera-debug branch, to experiment with camera there.

While it's hard for me to observe issue (so can't really verify), yet new camera should be closer in behavior to original.

Nindaleth commented 1 year ago

Thanks @Try! As of 0da61ba2, IMHO the lurching is exactly the same as before.

But there is one visible change to camera behaviour - I feel that the camera jumping up and down (as it precisely follows the character's bone moving vertically during the animation cycle) is much less pronounced -> more fluid and comfortable :-)

Try commented 1 year ago

Hm, @Nindaleth can you have a look into this on your side? Can't really see lurching on my end unfortunately ( given that nvidia driver introduces way more noticeable stutters :| )

Relevant parts are: Camera::followPos - control the green "rubber band": изображение (toggle camdebug here) and Camera::followCamera - the actual camera position following

Nindaleth commented 1 year ago

I'm not sure what to try changing in the camera code. I've enabled marvin mode + toggle camdebug and all I can see in both the green rubber band and the displayed data is that the camera very nicely follows the player; after a few steps the maximum distance of camera to the player is reached and then the distance fluctuates around 446-448 when running on an even ground from smithy to the south gate.

The lurching/forward movement speed inconsistency also appears in the walking animation, but is much less pronounced. It also happens in the crawl swimming animation very visibly on each hand stroke.

I believe that some frames of the running animation provide a different amount of forward travel. Since the swimming animation is much more pronounced, it's probably done on purpose in all animations, but it's just in the running animation that it feels wrong to me.

Try commented 1 year ago

I believe that some frames of the running animation provide a different amount of forward travel.

Yes, that is correct; also thank for the hint about swimming - can see a little of effect there

reached and then the distance fluctuates around 446-448 when running

When I tested swimming in vanilla fluctuations are in ~5-10cm amplitude

My current theory: camera distance can be broke down into 2 parts:

  1. Camera::followPos, painted in green
  2. Camera::followCamera painted in blue

изображение Based on vanilla testing: "green" one follows npc, slower than walking speed; with hard cap on distance.

Blue one, in that case is only one left to vary, and supposedly takes care of smooth camera translation. Blue one:

Try commented 1 year ago

Pushed new take on problem: ec37a23c

My new (yes, yet another one) theory here:

Camera speed seemingly is based on distance from destination point: my guess is min(green_len/script.best_range, 1)*max_speed

Nindaleth commented 1 year ago

Checked it, the smoothing of the forward motion is very good! I checked a bit of running and swimming and it's much better, I don't perceive any lurching at the moment.

Nindaleth commented 1 year ago

There is one thing - it seems that the current settings result in the camera being further behind the player than it is in master (EDIT: as in the maximum distance when running).

Try commented 1 year ago

it seems that the current settings result in the camera being further behind the player than

Previous model had issue: it FPS dependent, and behaves as expected at 200fps :( Push another take, now even more simplistic

Nindaleth commented 1 year ago

Looks good to me! The lurching is gone, the vertical bobbing on each step feels reduced to vanilla levels and I don't see any regressions. @mundifex are you able to verify on your end?

mundifex commented 1 year ago

Smooth as silk on my end when running the camera-debug branch 👍

Thanks for all your work on this! We can definitely consider this closed once it gets merged back to master.