Camera jitter and shake when player moves diagonally.

Hello,

I have camera following the player and when player moves diagonally everything in games starts to jitter and shake.

--Player code :--

keyLeft = keyboard_check(ord("A"));
keyRight = keyboard_check(ord("D"));
keyUp = keyboard_check(ord("W"));
keyDown= keyboard_check(ord("S"));

hspd = keyRight - keyLeft;
vspd = keyDown - keyUp;

inputDirection = point_direction(0,0,keyRight - keyLeft, keyDown - keyUp);
inputMagnitude = (keyRight - keyLeft != 0) or (keyDown - keyUp != 0);

//Movement
hspd = lengthdir_x(inputMagnitude * spd, inputDirection);
vspd = lengthdir_y(inputMagnitude * spd, inputDirection);


x += hspd;
y += vspd;
---------------------------------------------------------------
--Camera code: --
cx = camera_get_view_x(view_camera[0]);
cy = camera_get_view_y(view_camera[0]);

cx = lerp(following.x,mouse_x,0.1) - (view_w/2);
cy = lerp(following.y,mouse_y,0.1) - (view_h/2);

camera_set_view_pos(view_camera[0], cx, cy);

Is there any solutions for that?

Thanks in advance.
 

TsukaYuriko

☄️
Forum Staff
Moderator
Try rounding (or flooring) the coordinates of the camera. There are no fractions of pixels, so introducing them to anything visual-related may induce weird visual effects.

Also, these two lines
cx = camera_get_view_x(view_camera[0]);
cy = camera_get_view_y(view_camera[0]);
do absolutely nothing because you overwrite them instantly afterwards. If you were intending for these to have any sort of effect, they don't.
 
Try rounding (or flooring) the coordinates of the camera. There are no fractions of pixels, so introducing them to anything visual-related may induce weird visual effects.

Also, these two lines

do absolutely nothing because you overwrite them instantly afterwards. If you were intending for these to have any sort of effect, they don't.
Thank you for the answer. Looks like the player has stopped jittering, at least those jitters happen rarely and barely noticeable. Unfortunately the cursor still wobbles.
 

TsukaYuriko

☄️
Forum Staff
Moderator
If you'd like us to help you with that, please post any relevant code and maybe a GIF showcasing the issue.
 
If you'd like us to help you with that, please post any relevant code and maybe a GIF showcasing the issue.
Sorry for the delayed answer, was a bit busy. Well, the code I posted is almost everything I have. The cursor's code is missing, but it is a simple object following mouse_x/y positions.
Here is a gif showing the problem. Unfortunately it is only 25 fps but still possible to see the problem.
 
The cursor's code is missing
Lol, if you want help with something, we'll have to see the code. The problem might not be in the code, but we can't know until we see it and no-one wants to play suggestion ping-pong if the problem could've been solved at the start by seeing the code. So please post it alongside what event and object it is in.
 
Top