User Tag List

Page 1 of 4 1 2 3 ... LastLast
Results 1 to 10 of 40

Thread: walkTo() void?

  1. #1
    Octorok
    Join Date
    Jan 2008
    Age
    32
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    939
    Level
    10
    vBActivity - Bars
    Lv. Percent
    63.67%

    walkTo() void?

    Might also post at AG.

    Alright, what I need is a walkTo(int x1,int x2,int y1, int y2, int speed) void that would move something to x1 to x2 and to y1 to y2... I don't have any idea of how to do it, and I need it so much... I don't know much about trigonometry and such thing, so that's why I would need that one void... Help?

    And no loop... It's for use for scripts and such things.

    EDIT-Also, speed is how much to move the thing in pixels each time the void is executed.

  2. #2
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,142
    Level
    18
    vBActivity - Bars
    Lv. Percent
    10.54%

    Re: walkTo() void?

    Quote Originally Posted by lucas92 View Post
    Might also post at AG.

    Alright, what I need is a walkTo(int x1,int x2,int y1, int y2, int speed) void that would move something to x1 to x2 and to y1 to y2... I don't have any idea of how to do it, and I need it so much... I don't know much about trigonometry and such thing, so that's why I would need that one void... Help?

    And no loop... It's for use for scripts and such things.

    EDIT-Also, speed is how much to move the thing in pixels each time the void is executed.
    ARGH! The word you're looking for is "function". "void" is a return type. It means that a function does not return anything!

    *pant pant pant*

    As for your request. So, you want a function that moves... uh, a thing speed pixels in the direction of (x,y)?

    Well, an accurate implementation of the function would require an ATan function, which we don't have for some reason. Instead, I propose this naive substitute until we get such a function:

    Code:
    void moveTowards(ffc this, int x, int y, int speed) {
    	if(this->X < x) {
    		this->X += speed;
    	} else if(this->X > x) {
    		this->X -= speed;
    	}
    	
    	if(this->Y < y) {
    		this->Y += speed;
    	} else if(this->Y > y) {
    		this->Y -= speed;
    	}
    	
    }
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

  3. #3
    Octorok
    Join Date
    Jan 2008
    Age
    32
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    939
    Level
    10
    vBActivity - Bars
    Lv. Percent
    63.67%

    Re: walkTo() void?

    Oh that's great. :)

    Thank you. It was simpler than I thought. :)

  4. #4
    Octorok
    Join Date
    Jan 2008
    Age
    32
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    939
    Level
    10
    vBActivity - Bars
    Lv. Percent
    63.67%

    Re: walkTo() void?

    Wait a minute... It's not so much perfect that function... I mean, it would only go in a direction with a 45 degrees angle... And it isn't what I want...

    I guess I will use that one for now...

  5. #5
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,142
    Level
    18
    vBActivity - Bars
    Lv. Percent
    10.54%

    Re: walkTo() void?

    Well, I just circumvented the lack of ATan, and so you can use this supplemental script, and take its findAngle function to write this script:

    Code:
    import "std.zh"
    import "advmath.zh"
    
    void moveTowards(ffc this, int x, int y, int speed) {
    	int angle = findAngle(this->X, this->Y, x, y);
    	float dx = Sin(angle) * speed;
    	float dy = Sin(angle) * speed;
    	
    	this->X += dx;
    	this->Y += dx;
    }
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

  6. #6
    Octorok
    Join Date
    Jan 2008
    Age
    32
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    939
    Level
    10
    vBActivity - Bars
    Lv. Percent
    63.67%

    Re: walkTo() void?

    Wow. Just wow.

    No doubt I couldn't have done it.
    That's just great. Thanks. :)

  7. #7
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,142
    Level
    18
    vBActivity - Bars
    Lv. Percent
    10.54%

    Re: walkTo() void?

    DISCLAIMER: I have not tested any of this code, and only know that it compiles. However, if there's any problem with it, please let me know, and I will actually test it.
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

  8. #8
    Octorok
    Join Date
    Jan 2008
    Age
    32
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    939
    Level
    10
    vBActivity - Bars
    Lv. Percent
    63.67%

    Re: walkTo() void?

    Code:
    void moveTowards(ffc this, int x, int y, int speed) {
    	int angle = findAngle(this->X, this->Y, x, y);
    	float dx = Cos(angle) * speed;
    	float dy = Sin(angle) * speed;
    	if(this->X<x)this->X += dx;
    	if(this->X>x)this->X -= dx;
    	if(this->Y<y)this->Y += dy;
    	if(this->Y>y)this->Y -= dy;
    }
    Even with the mistakes I fixed, it seems to always follow a 45 degrees line then go up with a 0 degree line...

    I've made an example quest... Also try to avoid the armos, it will kill you in one hit... Anyway, I needed that function when it climbs the ceiling.

    http://www.mediafire.com/download.php?ytmzfjeemmc


    Also there are some mistakes in your advmath.zh file. Missed semicolons and such things.

  9. #9
    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,959
    Level
    33
    vBActivity - Bars
    Lv. Percent
    26.2%

    Re: walkTo() void?

    That's because pkmnfrk is modifying x,y coordinates based off floats instead of storing them in a seperate variable (such as Vx, Vy), I think. Try changing it to this->V and see if that works, or, use this instead:

    Code:
    void Homing(int speed, int ffc_num, int target_x, int target_y){
    	ffc F=Screen->LoadFFC(ffc_num);
    	int dx = target_x - F->X;
    	int dy = target_x - F->Y;
    	float norm = Sqrt(dx*dx+dy*dy);
    	if(norm > 0){
     		F->Vx = dx/norm*speed;
     		F->Vy = dy/norm*speed;
    	}
    }


    edit: Had a spontanious idea to make it better. (untested):

    Code:
    void Homing(int speed, ffc f, int target_x, int target_y){
    	ffc F=f;
    	int dx = target_x - F->X;
    	int dy = target_x - F->Y;
    	float norm = Sqrt(dx*dx+dy*dy);
    	if(norm > 0){
     		F->Vx = dx/norm*speed;
     		F->Vy = dy/norm*speed;
    	}
    }
    This post contains the official Gleeok seal of approval. Look for these and other posts in an area near you.

  10. #10
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,142
    Level
    18
    vBActivity - Bars
    Lv. Percent
    10.54%

    Re: walkTo() void?

    Well, my code should work if you change the second Sin to a Cos (brain fart).

    But, I would recommend against using the Vx and Vy variables for this purpose. Reason? If for some reason you stop calling moveTo(), the Vx and Vy variables won't magically revert to zero, and the ffc will continue to move.
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

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