Results 1 to 22 of 22

Thread: Moving an object on a linear path? *RESOLVED*

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    421

    Moving an object on a linear path? *RESOLVED*

    I'm still working on my game, and I want a better movement algorithm than the current. It's a 2D tile based game, and the current algorithm works something like this:

    VB Code:
    1. 'DestX and DestY refer to where the player clicked for the
    2. 'character to move, while CharX and CharY are the character's
    3. 'current position
    4.  
    5. Do Until CharX = DestX And CharY = DestY
    6.     If NewDest = True Then Exit Do
    7.    
    8.     If DestX > CharX Then CharX = CharX + 1
    9.     If DestX < CharX Then CharX = CharX - 1
    10.     If DestY > CharY Then CharY = CharY + 1
    11.     If DestY < CharY Then CharY = CharY - 1
    12.    
    13.     'draws the character in its new position
    14.     Call MoveCharacter(CharX, CharY)
    15. Loop
    That's no good because the character moves in a diagonal line until it reaches the same X or Y position as the destination, then moves in a straight line. I need the character to move in a diagonal line the entire time, heading towards the destination each turn.

    My theory is this: Get the slope of the character's position and the destination's position each turn, and move the character according to the slope. This could work, correct? If not, then what's another theory? Thanks.
    Last edited by Oafo; Nov 6th, 2002 at 11:10 PM.
    [vbcode]
    ' comment
    Rem remark
    [/vbcode]

Posting Permissions

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



Click Here to Expand Forum to Full Width