User Tag List

Results 1 to 7 of 7

Thread: Making an FFC move to a point

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

    Making an FFC move to a point

    So, to make an ffc move to a point, I need to set its vertical and horizontal speed to that which will move it to the point.

    My assumption on how to accomplish this was thus that V=S/t, therefore the speed that I want to give it for horizontal and vertical motion seperately will both be the distance I want it to travel, divided by the time I want it to get there in.

    So I have this:
    Code:
    		while(true){
    		x = Link->X;
    		y = Link->Y;
    		a = x - Link->X;
    		b = y - Link->Y;
    		c = a/20;
    		d = b/20;
    		if(this->X < x){this->Vx = c;}
    		if(this->Y < y){this->Vy = d;}
    		if(this->X == x){this->Vx = 0;}
    		if(this->Y == y){this->Vy = 0;}
    		Waitframe();
    		}
    I know it's a bit convuluted, but that's how I've done it. Why should this not work? It's just occured to me that the time that I've set for it to take has no units, so that may be a problem but I was assuming it shouldn't really be.

  2. #2
    The Time-Loop Continues ZC Developer
    Gleeok's Avatar
    Join Date
    Apr 2007
    Posts
    4,826
    Mentioned
    259 Post(s)
    Tagged
    10 Thread(s)
    vBActivity - Stats
    Points
    12,962
    Level
    33
    vBActivity - Bars
    Lv. Percent
    26.55%

    Re: Making an FFC move to a point

    Code:
    		if(this->X < x){this->Vx = c;}
    		if(this->Y < y){this->Vy = d;}
    That should work fine, and just add negative speed for >. ie:

    Code:
    		if(this->X > x){this->Vx = -c;}
    		if(this->Y > y){this->Vy = -d;}
    I'm no math wiz, but

    x = Link->X;
    y = Link->Y;
    a = x - Link->X;
    b = y - Link->Y;

    ...isn't that like saying

    a = 0
    b = 0

    ...
    This post contains the official Gleeok seal of approval. Look for these and other posts in an area near you.

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

    Re: Making an FFC move to a point

    now that's why it's not working. Thankyou Gleeok >_<
    Code:
    		while(true){
    		x = Link->X;
    		y = Link->Y;
    		a = x - this->X;
    		b = y - this->Y;
    		c = a/20;
    		d = b/20;
    		if(this->X < x){this->Vx = c;}
    		if(this->Y < y){this->Vy = d;}
    		if(this->X == x){this->Vx = 0;}
    		if(this->Y == y){this->Vy = 0;}
    		Waitframe();
    		}
    That's what I'm looking for.

  4. #4
    Octorok
    Join Date
    May 2007
    Posts
    331
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    1,509
    Level
    13
    vBActivity - Bars
    Lv. Percent
    12.44%

    Re: Making an FFC move to a point

    Here is an altrenate solution for you. If you dont' want to mess with Vx and Vy you can use this formula:
    Code:
    ffc script fetch{
    void run(int spd,int nX,int nY){
    int dx; int dy; int dist;
    dx = nX-this->X;
    dy = nY-this->Y;			 
    dist = Sqrt(dx*dx + dy*dy);
    while(this->X != nX && this->Y != nY){
    this->X += (dx / dist) * spd;
    this->Y += (dy / dist) * spd;
    Waitframe();
    }
    }
    }
    Argument0 is the speed the FFC will travel
    Argument1 is the X destination
    Argument2 is the Y destination

    Just some food for thought

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

    Re: Making an FFC move to a point

    So you're using pythagoras there? Why's that? I can't really work out what you're doing.

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

    Re: Making an FFC move to a point

    Quote Originally Posted by ShadowMancer View Post
    Here is an altrenate solution for you. If you dont' want to mess with Vx and Vy you can use this formula:
    Code:
    ffc script fetch{
    void run(int spd,int nX,int nY){
    int dx; int dy; int dist;
    dx = nX-this->X;
    dy = nY-this->Y;			 
    dist = Sqrt(dx*dx + dy*dy);
    while(this->X != nX && this->Y != nY){
    this->X += (dx / dist) * spd;
    this->Y += (dy / dist) * spd;
    Waitframe();
    }
    }
    }
    Argument0 is the speed the FFC will travel
    Argument1 is the X destination
    Argument2 is the Y destination

    Just some food for thought
    Remember though, if you move an ffc directly using X and Y instead of Vx and Vy, there are two things to bear in mind:

    (1) Movement may be less fluid depending on your code; and
    (2) FFCs that are set to "follow" the scripted FFC WILL NOT FOLLOW changes in X and Y, only Vx and Vy.

    It's find to use X Y, just don't run afoul of these limitations.

  7. #7
    Octorok
    Join Date
    May 2007
    Posts
    331
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    1,509
    Level
    13
    vBActivity - Bars
    Lv. Percent
    12.44%

    Re: Making an FFC move to a point

    (1) Movement may be less fluid depending on your code; and
    (2) FFCs that are set to "follow" the scripted FFC WILL NOT FOLLOW changes in X and Y, only Vx and Vy.
    Thank you, I was not aware of this (Mostly #2) As far as fluid movement, this is a chopped up version of the 'rapid fire enemy script' the part that aims at Link, it should work in the same way only aimed at nX, nY. Although if what you are aiming at is also moveing I could see a problem with fulid movement.
    I have not messed with Vx and Vy much at all, alot of my techniques come from my experience with GameMaker 5, I got so used to some built in varibles bieng either choppy , hard to use, or nonexistient so, force of habbit to use the most 'raw' functions possible :)

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