Results 1 to 4 of 4

Thread: Moving at angles

  1. #1

    Thread Starter
    Addicted Member drewski's Avatar
    Join Date
    Feb 2000
    Location
    WA
    Posts
    242

    Question Moving at angles

    I need to know how to move my sprite along a path at a certain angle. Can anybody help me with this?
    I see said the blind man as he spat into the wind.

    It all comes back to me now!

    A.D.T.'s VB

  2. #2
    Zaei
    Guest
    This is pretty easy. Take the angle, and convert it into a unit vector:
    Code:
    Type Vector
       x as Single
       y as Single
    End Type
    
    ...
    
    Dim dir as Vector
    dir.x = cos(angle)
    dir.y = sin(angle)
    Remember that angle must be in radians. If it is in degrees, you have to convert. just use the following:
    Code:
    radians = angle * (3.14159 / 180)
    ... and use radians in place of the angle variable above.

    Now, when you want to move, you need to know the speed you want to move your sprite at. Then, use this:
    Code:
    sprite.x = sprite.x + sprite.speed * dir.x
    sprite.y = sprite.y + sprite.speed * dir.y
    Z.

  3. #3

    Thread Starter
    Addicted Member drewski's Avatar
    Join Date
    Feb 2000
    Location
    WA
    Posts
    242

    Thumbs up

    Thanks man. That's exactly what I wanted. I'm going to try that out right now.

  4. #4
    Member SapphireGreen's Avatar
    Join Date
    Sep 2001
    Location
    I do not actually exist
    Posts
    45
    Yeah. It's common practice to do them as constants.

    Const PI = 3.14159
    Const RAD = PI / 180
    Const DEG = 180 / PI


    Pi, radians, degrees. There you are!
    On Error Give Up

    Mind over matter. Then if it doesn't matter, you lose your mind.

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