GML Camera Lerp isn't actually smooth.

seanm

Member
Hey, it's been a while since I've been on here. I'm back with another issue that most people will likely find to be too small to worry about, but I'm worryin about it.

My Problem
I'm using lerp to smoothly move my camera to my players position. Super basic camera that everyone does.

Code:
x += (objPlayer.x-view_wview[0]/2 - x) * lerpSpd
//or
x = lerp (x, objPlayer.x - view_wview[0]/2, lerpSpd)
However, what I've noticed is that this code actually makes the camera really shaky.
The camera will smoothly follow the player, but every ~4 frames the camera will stay in the same place.

Meaning there are constant stutters in the cameras movement. It decides it doesn't need to move on one frame, and then has to make a small jump to catch up on the next frame.

What do?
I think the stutter occurs when the camera gets close to its destination, ie the player.

One way I might be able to fix this:
  • Have the camera try to lerp the player back to the center of the screen,
  • but only activate the lerp when the player is a certain distance away from the center of the screen
This would make it so the lerp would be less likely to reach its destination because it gives the player a headstart.



Anyway, just wondering if anyone has thought about this, or has any ideas.

Cheers,
Sean
 

NicoFIDI

Member
Visual bugs without visual information are hard to guess...
is your game scaled?
how small it's the lerpSpeed?
also:
in what event you write this?

Making a whild guess:
you scale your game a lot, and you do it by GM scale.
then write something like
Code:
var distanceToPlayer = point_distance(objPlayer.x-view_wview[0]/2, objPlayer.y-view_hview[0]/2,x,y);
if (distanceToPlayer < 2) {
    x = objPlayer.x-view_wview[0]/2;
    y = objPlayer.y-view_hview[0]/2;
} else {
    //lerp code
}
check what values suits you.
 

icuurd12b42

TMC Founder
GMC Elder
your destination makes no sense. view width/2 as a destination? aint it supposed to be view x + view_width/2

try
x = lerp (x, view_xview[0] + view_wview[0]/2,.5);
or
x += (view_xview[0] + view_wview[0]/2-x) * .5;

this should do a inverse log2 movement to the target
 
M

MariusArmand

Guest
I believe I had this issue when I scaled for the wrong aspect ratio..
 

seanm

Member
Yeah, this was code in a camera object.
The destination of the camera is supposed to be the players coordinates, minus half the width and height of the view. This puts the player in the center of the screen.

If the target of the camera was just the player's coordinates, the player would be stuck in the top left corner of the screen.


Anyway, I think I might have found out what my problem is.
It seems when I run my game in fullscreen, it runs really choppy. If I alt+tab out and then re-fullscreen my game, it runs much smoother.

Though this might just be an issue with my PC so I could just be screwed here. Probably not much anyone could say to help troubleshoot.


edit: actually I found the source of that issue anyways. Was in the Nvidia control panel: Preferred refresh rate was set to "highest available", instead of "application controlled". I guess it was trying to vsync the game to 60hz, but running the monitor at 144hz. Changing it back to application controlled fixed the stuttering issue.
 
Last edited:

icuurd12b42

TMC Founder
GMC Elder
sorry my code is ****e lol and yours was right. assuming lerpSpd was >0 and <= 1 it should work

x = lerp (x, objPlayer.x - view_wview[0]/2, .5)

would give the reverse log2 smooth movement...

Full screen is utterly broken for me so your stuttering issue may be related.
 

seanm

Member
Yeah simple mistake, no worries.

How is your fullscreen broken? What seems to be the issue?
 

seanm

Member
@icuurd12b42
If you're getting a white screen you might want to try turning vsync on/off. One of them fixes it.

I think its a gamemaker bug with windows 10.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Moderator
I think its a gamemaker bug with windows 10.
I'm pretty sure this is an issue with nVidia drivers and Windows 10, and not a bug with GMS. Everything worked fine before the Creators Update to windows 10, and if you search the internet you'll find references to many games (Dark Souls, Battle Block Theater, and a number of others) that have the same problem.
 

Moth27

Member
I know this is old but I ran a test on this and the "JITTER" was due to using "/" instead of "div"
also the lerp speed should be something like (1, 0.5, 0.25, 0.2, or 0.1)
 
Top