User Tag List

Results 1 to 2 of 2

Thread: Vector Velocity Movement

  1. #1
    Wizrobe C-Dawg's Avatar
    Join Date
    Jan 2002
    Posts
    4,205
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    6,612
    Level
    24
    vBActivity - Bars
    Lv. Percent
    99.95%

    Vector Velocity Movement

    I'd like an algorithm that will send an FFC shooting out in a given direction at a pre-set speed. It's the math part that's giving me trouble.

    INPUT: ( slope of a line, direction, speed )

    The slope is just the slope of the line the FFC is to shoot along. The direction is the way it will move along that slope. Specifying East or West should be enough, since it's a single linear line, except in the case of purely vertical movement. Then the speed should be how fast it moves along that line.

    BEHAVIOR

    The FFC should move along the slope of a line defined by the slope relative to it's starting position. This is fairly easy; x + 1 and y + slope will do it. (Rise over run, as I recall.) But in addition to moving on this line, it should move AT A CONSTANT SPEED, no matter in what direction it's headed. This is the tricky bit I'm having trouble with.

    Speed is going to be determined by distance over time, or

    Speed = Distance / Time

    We'll just talk about one tic, so time = 1. And we use the distance formula to get the distance from our known current FFC positon (x1, y1) to our new position (x2, y2).

    Speed = (x1-x2)^2 + (y1-y2)^2

    Where the knowns are speed, x1, and y1, and the unknowns are x2 and y2. I can't solve this equation for those variables, so I'm sort of stuck.

    I'm probably going about this the wrong way. Saffith, your thoughts?

  2. #2
    Is this the end?
    ZC Developer
    Saffith's Avatar
    Join Date
    Jan 2001
    Age
    41
    Posts
    3,389
    Mentioned
    178 Post(s)
    Tagged
    6 Thread(s)
    vBActivity - Stats
    Points
    6,433
    Level
    24
    vBActivity - Bars
    Lv. Percent
    70.12%

    Re: Vector Velocity Movement

    I think I know how to go about this, if I'm understanding you correctly...

    Movement at a given angle is easy:
    vx = speed * cos(angle)
    vy = speed * sin(angle)

    The difficulty in this case is in finding the angle, but you should be able to skip that step altogether.
    First, construct a triangle:
    Code:
             /|
            / |
    slope  /  |  sqrt(slope^2-1)
          /   |
         /    |
           1
    Then, of of course, you can find the sine and cosine directly by dividing the sides appropriately. Thus:
    vx = speed * 1 / slope
    vy = speed * sqrt(slope^2-1)
    And you just make those both negative to move the opposite direction. Moving vertically is a special case, obviously, but it's a pretty easy one.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Armageddon Games is a game development group founded in 1997. We are extremely passionate about our work and our inspirations are mostly drawn from games of the 8-bit and 16-bit era.
Social