• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker [SOLVED] Player twitches while moving

D

DeadZombie

Guest
Hello everyone!
Could anyone, please, explain how to make player move smoothly? By default it looks very bad, player twitches while moving X or Y and effect is increasing with diagonal movement. Sometimes I can even notice small changing of pixel color of the outline of a character. Black comes to gray.

Windows settings: 60FPS.

Are there any tutorials or rules concerning that kind of issues? I mean, what movement smoothing depends on? The grid size? Sprites settings?

 
D

DeadZombie

Guest
Sure, for movement, I used the code from tutorial:

 
Last edited by a moderator:

NightFrost

Member
Your vertical collision check wrong is it is mostly a direct copy of the horizontal. But judging by your screenshot, you were in the process of fixing it?
 
D

DeadZombie

Guest
Your vertical collision check wrong is it is mostly a direct copy of the horizontal. But judging by your screenshot, you were in the process of fixing it?
Yes. Actually, it's a screenshot from the tutorial, I just don't have access to my own code right now. I've changed screenshot :)
 

Relic

Member
Are move x and move y non integers? The character can’t be drawn perfectly at position 325.27 so instead the sprite is drawn with some interpolation so that is kind of looks like it is at 325.27.

You can turn off interpolation between colours in the graphic settings - however that grey pixel will probably turn into two black pixels while you are hoping for one.

Another solution is to round the player’s position -
x=round(x)
Same for y.

However this may cause slight issues with movement, particularly if you have acceleration included in the movement code. So it will probably suffice just to round the drawing coordinates in the draw event-

draw_sprite(round(x),round(y),sprite_index,image_index)
 
D

DeadZombie

Guest
Thank you, Relic, I'll try your solution this evening and let you know how it goes.
 
N

NeZvers

Guest
@Relic don't round, you'll get the same result.
I would use moveX = floor(moveX) * sign(moveX); before while loop
Although there's more to it with this rounding, for a start, it will work.
 
Last edited:
E

Edwin

Guest
If you want, you can round the hundredth fracture of the value with this little script:

Code:
/// round_frac(val)

// Get argument
var value = argument[0];

// Round fraction
var round_function = exp(1 * ln(10));
var output = round(round_function * value) / round_function;

// Return non-integer
return output;

We set x = 83.35 for example.

round(x) will return 83.00,
round_frac(x) will return 83.30.
 
N

NeZvers

Guest
@Edwin, you need to round down to pixel, not fraction of pixel, but thanks for the neat script.
 
D

DeadZombie

Guest
I'm still there, rounding moveX and moveY did not bring any result :(
Here is the full code regarding movement:
Code:
//------MOVEMENT------

input_right = keyboard_check(ord("D"))
input_left = keyboard_check(ord("A"));
input_up = keyboard_check(ord("W"));
input_down = keyboard_check(ord("S"));

moveX = 0;
moveY = 0;

//------INTENDED MOVEMENT
moveX = input_right - input_left;
moveY = input_down - input_up;

if(moveX != 0 or moveY != 0){
    dir = point_direction(0,0,moveX,moveY);
 
    //------NORMALIZE SPEED
    moveX = lengthdir_x(spd, dir);
    moveY = lengthdir_y(spd, dir);

    //------COLLISION CHECKS
    //horisontal
    if(place_meeting(x+moveX, y, obj_collider)){
        repeat(abs(moveX)){
            if(!place_meeting(x+sign(moveX), y, obj_collider)){
            x += sign(moveX);
            } else {
                break;
            }
        }
        moveX = 0;
    }
 
    //vertical
    if(place_meeting(x, y+moveY, obj_collider)){
        repeat(abs(moveY)){
            if(!place_meeting(x, y+sign(moveY), obj_collider)){
                y += sign(moveY);
            } else {
                break;
            }
        }
        moveY = 0;
    }

    //------APPLY MOVEMENT
    y += round(moveY);
    x += round(moveX);
    image_speed = 2.5;
 
    //------SET SPRITES
    switch(dir){
        case 0: sprite_index = spr_knight_walk_front;
            break;
        case 45: sprite_index = spr_knight_walk_front;
            break;
        case 90: sprite_index = spr_knight_walk_front;
            break;
        case 135: sprite_index = spr_knight_walk_front;
            break;
        case 180: sprite_index = spr_knight_walk_front;
            break;
        case 225: sprite_index = spr_knight_walk_front;
            break;
        case 270: sprite_index = spr_knight_walk_front;
            break;
        case 315: sprite_index = spr_knight_walk_front;
            break;
    }
} else {
    sprite_index = spr_knight_idle_front;
    image_speed = 1;
}
@Relic don't round, you'll get the same result.
I would use moveX = floor(moveX) * sign(moveX); before while loop
Although there's more to it with this rounding, for a start, it will work.
When I put "moveX = floor(moveX) * sign(moveX);" (and same for Y) before my repeat blocks - the character starts moving wrong. "A" and "D" both make him move RIGHT, and "A" makes him walk twice faster. The same thing with "W" and "S". But even so - the twitching problem is still reproducing.

Also, I've noticed that whenever charachter moves along with the camera - there are no strobbing/twitching/lagging, everything is smooth. Thus I suppose the problem is not in rounding of speed, but in the way how character sprite is drawn.
I keep googling, but can't find anything :(
 
D

DeadZombie

Guest
EDITED: Maybe I'm too picky? Maybe this twitching is a part of all games? :) Is there any option to publish .exe file so you guys could take a look?
 
Last edited by a moderator:

Relic

Member
If you have a camera , try rounding off the camera positions too.

It is also possible it’s a screen thing. I couldn’t actually see the issue on my phone- but I don’t have much of an eye for these art things anyway.
 
Looks to me like there's a little bit of v-sync tearing going on as well. Maybe try turning on Options >> Windows >> Use synchronization to avoid tearing. Another "fix" to this issue is to have the character remain in the dead center of the camera, but if you do that, you'll have to allow the 'outside' of the room to show (it'll be black by default, but you could add tiles around the outside of the room for half the camera width/height to give the illusion that it's just more area).
 
D

DeadZombie

Guest
Looks to me like there's a little bit of v-sync tearing going on as well. Maybe try turning on Options >> Windows >> Use synchronization to avoid tearing. Another "fix" to this issue is to have the character remain in the dead center of the camera, but if you do that, you'll have to allow the 'outside' of the room to show (it'll be black by default, but you could add tiles around the outside of the room for half the camera width/height to give the illusion that it's just more area).
That's exactly what I was thinking about! But in case of fixing character tearing/twitching would hurt the whole environment. I mean the whole camera viewport would start tearing. And by the way, I have just looked at SEGA's 'Zombies Ate My Neigbours' and that issue is actually there (!), while player is moving along with the camera, the rest of the screen tears/twitches and even some ugly lines appear from time to time on a screen (sort of a distortion), which makes me think, that this is a normal behavior :(
 
Did you try turning on Use synchronization to avoid tearing? The reason that v-sync happens is that only half (or thereabouts) of a frame gets calculated before it needs to calculate the next frame, so everything gets rendered half one frame and half another (so the top half of a moving object would be displaced by a little bit compared to the frame that renders its bottom half). The Use synchronization to avoid tearing option makes sure that each frame is fully rendered and only that frame is displayed, so it should remove this issue (but it can slow the game down in worst case scenarios, though given that we are working in 2d environments without massive rendering requirements, in reality, it shouldn't slow down your game unless you code is horribly inefficient). The common name for Use synchronization to avoid tearing is v-sync (obviously, you already know what v-sync is, but just pointing out that this is the game maker parlance for it).
 
Last edited:
D

DeadZombie

Guest
Did you try turning on Use synchronization to avoid tearing? The reason that v-sync happens is that only half (or thereabouts) of a frame gets calculated before it needs to calculate the next frame, so everything gets rendered half one frame and half another (so the top half of a moving object would be displaced by a little bit compared to the frame that renders its bottom half). The Use synchronization to avoid tearing option makes sure that each frame is fully rendered and only that frame is displayed, so it should remove this issue (but it can slow the game down in worst case scenarios, though given that we are working in 2d environments without massive rendering requirements, in reality, it shouldn't slow down your game unless you code is horribly inefficient). The common name for Use synchronization to avoid tearing is v-sync (obviously, you already know what v-sync is, but just pointing out that this is the game maker parlance for it).
I didn't. I'll try this after work and let you know! :)
 
D

DeadZombie

Guest
Unfortunately, v-synch does not give anything :( I'm really confused. Look what happened when the character moves with following camera!

And this video shows how char moves with static camera:
 
Last edited by a moderator:

Kyon

Member
This is something I ran in to with my game as well (because I zoom in a lot).
It's indeed because of the low resolution. Most low resolution or pixel games scale their graphics up (like with a surface), so that movement feels smooth.
 
D

DeadZombie

Guest
This is something I ran in to with my game as well (because I zoom in a lot).
It's indeed because of the low resolution. Most low resolution or pixel games scale their graphics up (like with a surface), so that movement feels smooth.
I'm afraid it's not because of low resolution. This is an example with 1280x720 and the object has sprite 200x200 px. The issue is reproducing both in windowed and full screen mode :(
This video is from the new project, with no heavy code, only basic movement.
Playing with 'sleep margin', 'interpolate', 'v-synch', 'fps' as well as 'round(x) and y', 'floor(x) and y' didn't give any positive result. I don't know what to do. Is that what all GMS2 developers live with?
 
Last edited by a moderator:
D

DeadZombie

Guest
Is there any chance to get any info from GMS2 developers or tech support?
 
D

DeadZombie

Guest
I think, finally, I've found out what was the problem. Playing with resolutions I see different behavior of moving objects. Even outline of character can be harmed by another resolution. I suppose the pixels can't be only square?
 
I

InvisaBlind

Guest
toggle your speed a bit.

maybe:
hsp = 0
vsp = 0
walksp = 3.5
 

NightFrost

Member
I suppose the pixels can't be only square?
Pixels - as in pixels that make out the display - can only be square, but in case you're stretching the view, and doing it out of aspect ratio and/or not in integer multipliers, the game won't get evenly stretched across multiple pixels.
 
D

DeadZombie

Guest
Maybe it's your graphic card or CPU? Did you update them?
What do you mean? Hardware update? I've got old i7-3770 @ 3.4 GHz and GTX 1060 6GB. Video driver is up to date.
 
D

DeadZombie

Guest
Right now I got stable smooth movement picture with vsync ON and windowed mode. But there are strange horizontal lines appear from time to time produce tearing. I see the same lines when play SEGA :) But the main problem is still reproducing at fullscreen mode.
WINDOWED MODE: Interesting, but my smooth movement disappears whenever I start recording video from the desktop and I see tearing and twitching in real time. When I finish and shut down monosnap recording, smooth movement returns.
 
D

DeadZombie

Guest
Here is the video with horizontal line, which is really annoying:

I see it in GMS2 tutorials on youtube as well, but games created by PRO studios havn't it. For example Feral-Fury
 
N

NeZvers

Guest
Those lines appear only when you have vsync off. Check manual how to do t
On fullscreen you loose that smooth movement because your resolution and aspect ratio doesn’t match display. For that you need to watch Pixelated Pope tutorial if you are not familiar on how to calculate right resolution.
 
D

DeadZombie

Guest
The problem finally solved!

Those lines appear only when you have vsync off. Check manual how to do t
On fullscreen you loose that smooth movement because your resolution and aspect ratio doesn’t match display. For that you need to watch Pixelated Pope tutorial if you are not familiar on how to calculate right resolution.
I saw that tutorial and thanks to it I've found out much of valuable information about display, camera, views and stuff. But the problem wasn't connected with resolution.
Everything went fine and smooth once I switched Windows theme to Aero. And the reason why it happens is because Aero theme USES composite manager.

NOTE: according to my researches, in case of Ubuntu same things might happen bacause of Compiz visual effects, so be aware of using it!

https://en.wikipedia.org/wiki/Compositing_window_manager

Thanks guys for all your replies, it was a long road to the source of the problem and all of you helped, I appreciate it very much!
 
Last edited by a moderator:
E

Edwin

Guest
The problem finally solved!



I saw that tutorial and thanks to it I've found out much of valuable information about display, camera, views and stuff. But the problem wasn't connected with resolution.
Everything went fine and smooth once I switched Windows theme to Aero. And the reason why it happens is because Aero theme works without composite manager.

NOTE: according to my researches, in case of Ubuntu same things might happen bacause of Compiz visual effects, so be aware of using it!

https://en.wikipedia.org/wiki/Compositing_window_manager

Thanks guys for all your replies, it was a long road to the source of the problem and all of you helped, I appreciate it very much!
Finally it's solved. :)
 
Top