Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 23

Thread: How to achieve smooth movement

  1. #11

    How to achieve smooth movement

    OK cheers. I will play around with those ideas and see if I can improve it. Many people have trouble seeing what I mean when I show them so it is not too bad
    The views expressed on this programme are bloody good ones. - Fred Dagg

  2. #12

    Re: How to achieve smooth movement

    Quote Originally Posted by czar
    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.
    This part sounds confusing to me, I have never had any problems with unsmooth movement using the timers i've created for Phoenix for instance. What kind of timer do you use and how do you calculate the elapsed time ?

    Some example code on how i'm doing it:
    Code:
      var   Frequency   : Int64;
      var  CurrentTime: Single:
      var  LastTime     : Single:
      var  FrameTime  : Single:
    
      procedure Initialize;
      begin
        QueryPerformanceFrequency(Frequency);
      end;
      
      procedure Update;
      var Time : Int64;
      begin
        QueryPerformanceCounter(Time);
    
        CurrentTime:= (Time / Frequency);
    
        FrameTime:= CurrentTime - LastTime
    
        LastTime:= CurrentTime;
      end;
    
      procedure MoveSprite;
      begin
        Sprite.X:= Sprite.X + Sprite.Velocity.X * FrameTime;
      end;
    (note that this is limited to Pentium 3's and above)

    If the framerate varies alot you could average the frame time over a few frames aswell to get even smoother movement.
    Amnoxx

    Oh, and this code appears to be an approximate replacement for return(random() & 0x01);

    Phoenix Wiki
    http://www.phoenixlib.net/

    Phoenix Forum
    http://www.pascalgamedevelopment.com/viewforum.php?f=71

  3. #13

    How to achieve smooth movement

    I have been playing around with different variables and the ideas mentioned above and I have figured out that the best movement in my case comes from:

    Vsync set, No limited on Max FPS.

    OK, excellent guys. I think I will stick with that. I have kept CPU usage to a minimum (1-2% on my machine) in order to prevent the fan coming on in people's laptops.

    I am testing this with DanJetX however my concern was not limited to DanjetX because I have also seen it with Omega and DelphiX.
    The views expressed on this programme are bloody good ones. - Fred Dagg

  4. #14

    How to achieve smooth movement

    Yeah I've also have a problem with those small jitters which seems to be randomly. As far as I know a lot of people have problem with it. It could be even observed on the DelphiX collision demo. The one in which you move a ball to collide with other balls.

  5. #15

    How to achieve smooth movement

    czar,
    in the latest version of DanJetX (0.75) the timer has a Process procedure
    where you can simply stick all your movement without worrying about
    frame dependency (no need to multiply by any speed factor or calculate lags).

  6. #16

    How to achieve smooth movement

    Quote Originally Posted by czar
    Can you expand upon what you mean by frame number
    Let's say the display is configured for 100Hz. Frame 1 is displayed at t=0,01 and frame 2 is displayed at t=0,02.

    Now, say you are moving a sprite on the screen, frame 1 has just been drawn and you are drawing frame 2. If you use the system time, you will get a value between 0,01 and 0,02. If you use this value to calculate the position of the sprite, this will be sligthly off, and slightly unpredictable. The right value to use is 0,02 and not the value somewhere between 0,01 and 0,02 because t=0,02 when the frame will be actually shown.

  7. #17

    How to achieve smooth movement

    @Dan: Right now I am doing it exatly like Czar does. If I want to use the new timer.process, what do I have to change in the movement?
    Just move it let's say 4 to the right instead of move it 4*time_elapsed to the right?

    Can this also be used for randoms? When I want my sprite to do something from time to time I use random(round(1000*time_elapsed))=0...Interesting thread this is

    Firle

  8. #18

    How to achieve smooth movement

    These jerks occurs when a videodriver performs a CPU-GPU syncronization.
    You can force the syncronization every frame by reading one pixel from backbuffer or draw something via GDI.
    Also sleep(10-30) after D3DDeivce.Present() may help.
    All these methods have some FPS cost.

  9. #19

    How to achieve smooth movement

    @Mirage - I haven't heard of this before - have you any idea where I could find more info on this? I will google it when I get to work.
    The views expressed on this programme are bloody good ones. - Fred Dagg

  10. #20

    How to achieve smooth movement

    Quote Originally Posted by czar
    @Mirage - I haven't heard of this before - have you any idea where I could find more info on this? I will google it when I get to work.
    Video card vendors usally publishing related information on their sites.
    http://developer.nvidia.com/page/home.html
    Also forums on sites like gamedev.net are good source of information.

Page 2 of 3 FirstFirst 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
  •