#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Unhappy How would I move an object smooth and fast?


    So lets say I have unit vector 'a' as direction.
    To move an object to the direction I would use
    object.Position=object.Position + a*speed, right?

    If the speed would be something like 5 it would just teleport 5 units towards the direction..

    I could use some loops to move it and keep the speed under 1 unit..But..

    That's slow since the smallest sleep would be the time from frame to another frame.

    I can't get an object to move smooth and fast...
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,730
    Rep Power
    1959
    To get something smooth, you should have at least 30 frames per second (fps) and higher is better.

    You say you want to move it fast with 5 unit in speed, but speed is defined by the distance over a specific time.

    You have to ask if the speed should be 5 unit/frames directly or 5 unit/second.
    If you want to work with seconds, you will then have to calculate the unit/frames, depending at the fps.

    e.g. 5 unit/second with 30 fps will have the actual frame speed at 0,16 unit.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Question


    Originally Posted by MrFujin
    To get something smooth, you should have at least 30 frames per second (fps) and higher is better.

    You say you want to move it fast with 5 unit in speed, but speed is defined by the distance over a specific time.

    You have to ask if the speed should be 5 unit/frames directly or 5 unit/second.
    If you want to work with seconds, you will then have to calculate the unit/frames, depending at the fps.

    e.g. 5 unit/second with 30 fps will have the actual frame speed at 0,16 unit.
    So..
    Some-kind of a loop with smallest sleep and;
    position = position+direction*0.16

    ?
  6. #4
  7. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,730
    Rep Power
    1959
    Try it and see how it looks.

    But if you only have that calculation in a loop, it will go much faster than the "5 unit/second".

    For example, in my test, it takes about 5 milliseconds to get from 0 to 5 with a step at 0.16 while it prints out "Hello World". (tested with Java)

    But this is of course without any use of sleep "cheating"

IMN logo majestic logo threadwatch logo seochat tools logo