Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: How to achieve smooth movement

  1. #1

    How to achieve smooth movement

    My pet annoyance for a long time has been smooth movement. Why is it so difficult to move say a large game sprite from one side of the screen to the other without jittering?

    I am hoping people have some suggestions to help improve the way in which sprites can be moved.

    Typically the way I do it is as follows.

    The coordinates of a 2d or 3d sprite are x,y,z as a single or double.

    current location is updated using the speed lag of the system. i.e. the number of milliseconds it takes for the computer to come back and run through a timer loop.

    So; x :=x + (100 * Timerlag);

    Where timerlag is a proportion for example 16 ms divided by 1000. The 16 ms is the time it takes for the computer to run through the timer again. Using this system I should find that my object travels 100 pixels in one second, and on the whole looks ok. However I find that the movement is never consistent and that the object tends to jerk every once in a while. This is not so noticeable in a game where a sprite constantly switches directions, but it is noticeable when you have a large object that needs to "slide" from one place to another.

    With 3d objects I can leave the x,y,z coords as singles but for 2d stuff the sprite is usually drawn by trunc(x). In both cases I still see jerky movements.

    I have tried a few optimizations; like finding an average for timerlag over N number of frames and then use that value instead of a constantly changing value. This work to some extent. It has the added benefit that it is not possible for the sprite location to all of a sudden change by a large amount. I have had this occur in the past, Windows would all of a sudden decide to put time into accessing an idle drive and the resulting timerlag would send a sprite straight through a wall or similar.

    How do others move their sprites and has any one got an idea to improve the smoothness or consistency of movement?
    The views expressed on this programme are bloody good ones. - Fred Dagg

  2. #2

    Re: How to achieve smooth movement

    Quote Originally Posted by czar
    With 3d objects I can leave the x,y,z coords as singles but for 2d stuff the sprite is usually drawn by trunc(x). In both cases I still see jerky movements.
    Assuming that you use Direct3D, why do you truncate coordinates? Just use floats and image will "swim" smoothly. This may generate extra blur, but transitions will be very smooth, especially if using multisampling.

  3. #3

    How to achieve smooth movement

    I only truncate for functions that require the coords in integer rather than doubles. e.g. for older delphix stuff. However where possible I do leave it as floats.
    The views expressed on this programme are bloody good ones. - Fred Dagg

  4. #4

    How to achieve smooth movement

    Vsync is very important for smooth movement. Enable vsync, and use the frame number as the basis of the positions where you draw (if you use the system time there will be a small timing jitter as the frame will only be drawn=shown at the next vsync).

  5. #5

    How to achieve smooth movement

    Can you expand upon what you mean by frame number?

    Are you saying you move a fixed amount per frame? If so then speed will be dependent on frame rate, faster frame rate, faster game. That would not be good for computers that cannot keep a steady 60 FPS or whatever you set it at.
    The views expressed on this programme are bloody good ones. - Fred Dagg

  6. #6

    How to achieve smooth movement

    what you are seeking is called "timebased movement".

    timebased movement is achieved by measuring the time your last frame
    took to render multiplied by the units you want to move per second.

    maybe you've got it right anyway, i just don't understand what you mean
    by "time it takes for the computer to run through the timer again" so i
    thought i'll post just to be sure.

    see http://www.devmaster.net/wiki/Timing

    hope it helped :D

  7. #7

    How to achieve smooth movement

    That is exactly what I am doing. It is all timebased rather than frame based.
    The views expressed on this programme are bloody good ones. - Fred Dagg

  8. #8

    How to achieve smooth movement

    could you explain what you mean by "time it takes for the computer to run through the timer again" ?

    Does this mean you'r calculating the amount of time the last frame took to complete?

    if so, then i really can't think of a reason why animation is jerky... never
    had this kind of problem (and i always use timebased movement...).

    sorry for not being able to help :)

  9. #9

    How to achieve smooth movement

    Most drawings system have it. It is the lag between rendering.

    I think you misunderstand when I say it is jerky I am not talking about gross movement I am talking about small jitters that occur sometimes - not noticeable to the average joe.

    If I have time I will put a simple example together and post it.

    By the sounds of I do my movement the same way as everyone else so I think I will need to learn to live with it.
    The views expressed on this programme are bloody good ones. - Fred Dagg

  10. #10

    How to achieve smooth movement

    Try to run the application in full-screen and disable vsync. This will give higher rendering frame rate (unless you are limiting it, which is probably the source of jitter) and increase the precision of frame-based movement.

    Also try to optimize your rendering pipeline, since the source of jitter is probably when either your application or Direct3D falls behind the rendering, so Present() takes significantly more time to render than normally.

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •