User Tag List

Results 1 to 4 of 4

Thread: Sine wave at an angle?

  1. #1
    &&
    ZC Developer
    Joe123's Avatar
    Join Date
    Sep 2006
    Age
    32
    Posts
    3,061
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    7,304
    Level
    26
    vBActivity - Bars
    Lv. Percent
    8.83%

    Sine wave at an angle?

    At the moment, I have a movement routine for an enemy worked out to follow a straight line between two points, using y = mx +c.

    I want to make it also move in a sine wave sort of pattern, but along that line...

    I can only think of how to make things move in a sine wave along a horizontal or vertical line though.

    Anyone have any ideas as to how I'd go about doing this?

  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.17%

    Re: Sine wave at an angle?

    Just think of the wave movement as an offset along a line perpendicular to the direction you're moving. Something like this:
    Code:
    while(true)
    {
        // Undo previous frame's offset
        this->X-=offset*Cos(angle+90);
        this->Y-=offset*Sin(angle+90);
        
        // Move along the overall angle
        this->X+=speed*Cos(angle);
        this->Y+=speed*Sin(angle);
        
        // Find the offset from the straight line
        offset=amplitude*Sin(i);
        
        // Offset movement
        this->X+=offset*Cos(angle+90);
        this->Y+=offset*Sin(angle+90);
        
        i=(i+1)%360;
        Waitframe();
    }

  3. #3
    &&
    ZC Developer
    Joe123's Avatar
    Join Date
    Sep 2006
    Age
    32
    Posts
    3,061
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    7,304
    Level
    26
    vBActivity - Bars
    Lv. Percent
    8.83%

    Re: Sine wave at an angle?

    I shall...

    ...have a look and try to decipher that.

    Thanks ^_^

  4. #4
    &&
    ZC Developer
    Joe123's Avatar
    Join Date
    Sep 2006
    Age
    32
    Posts
    3,061
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    7,304
    Level
    26
    vBActivity - Bars
    Lv. Percent
    8.83%

    Re: Sine wave at an angle?

    Oh, I had it moving using y=mx+c to move it along the line, but this uses sine and cosine to do that, doesn't it?

    Hrm ok.



    EDIT: With a little fiddling, and a complete conversion to radians it now works ^_^
    Thanks.

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