User Tag List

Page 2 of 4 FirstFirst 1 2 3 4 LastLast
Results 11 to 20 of 40

Thread: walkTo() void?

  1. #11
    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.21%

    Re: walkTo() void?

    Heh, I didn't see that either. :eyebrow:

    I've had less than adequate results in the past with ZC trying to modify an objects screen position with decimal places though. (I stopped doing it altogether actually) Just thought I'd point that out.
    This post contains the official Gleeok seal of approval. Look for these and other posts in an area near you.

  2. #12
    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.56%

    Re: walkTo() void?

    Well, I don't see any particular reason why it wouldn't work (assuming the engine doesn't truncate the positions), but if you're concerned about it:

    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 = Cos(angle) * speed;
    	
    	this->X += Floor(dx);
    	this->Y += Floor(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!

  3. #13
    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.72%

    Re: walkTo() void?

    Cool I'll try that out... Btw, happy new year! :)

  4. #14
    &&
    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,303
    Level
    26
    vBActivity - Bars
    Lv. Percent
    8.74%

    Re: walkTo() void?

    Quote Originally Posted by Gleeok View Post
    I've had less than adequate results in the past with ZC trying to modify an objects screen position with decimal places though. (I stopped doing it altogether actually) Just thought I'd point that out.
    Code:
    while(true){
    	Link->X += move(this->Vx,counterx);
    	Link->Y += move(this->Vy,countery);
    	counterx = (counterx+1)%(100/factors100(Abs(this->Vx)));
    	countery = (countery+1)%(100/factors100(Abs(this->Vy)));
    }
    int move(int s,int c){
    	int as = Abs(s);
    	int ret;
    	if(as < 1){
    		if(c < as*100/factors100(as)) ret = 1;
    		else ret = 0;
    	}else if(as < 2){
    		if(c < (as-1)*100/factors100(as-1)) ret = 2;
    		else ret = 1;
    	}
    	if(s < 0) ret = -ret;
    	return ret;
    }
    int factors100(int s){
    	for(int i=50;i>0;i--) if((s*100)%i == 0) return i;
    }
    Takes a speed, and moves an object that doesn't have a Vx/Vy value at that speed. Currently works (well, it works mostly. Some speeds are a little out) for speeds from 0 to 2 (not inclusive).

    I'm sure it's not the best way, but I'm quite proud of it. Took me a while to think up.

    Obviously you can't actually move an object by half a pixel, that just doesn't make sense.

  5. #15
    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.72%

    Re: walkTo() void?

    Quote Originally Posted by pkmnfrk View Post
    Well, I don't see any particular reason why it wouldn't work (assuming the engine doesn't truncate the positions), but if you're concerned about it:

    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 = Cos(angle) * speed;
    	
    	this->X += Floor(dx);
    	this->Y += Floor(dx);
    }
    That still doesn't work... It goes an another time with a 45 degrees line...
    Also goes always right when it has to go left...

  6. #16
    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.56%

    Re: walkTo() void?

    Quote Originally Posted by lucas92 View Post
    That still doesn't work... It goes an another time with a 45 degrees line...
    Also goes always right when it has to go left...
    Hang on, maybe I'll just, you know, test it.

    EDIT: For cripes sake. I figured out why I was stupid.

    Code:
    import "advmath.zh"
    
    void moveTowards(ffc this, int x, int y, int speed) {
    	int angle = findAngle(this->X, this->Y, x, y);
    	float dx = RadianSin(angle) * speed;
    	float dy = RadianCos(angle) * speed;
    	
    	this->X += dx;
    	this->Y += dy;
    }
    
    ffc script followLink {
    	void run() {
    		while(true) {
    			moveTowards(this, Link->X, Link->Y, 1);
    			Waitframe();
    		}
    	}
    }
    I fixed a typo, and remembered that findAngle uses Radians, not Degrees. So, I switched Sin and Cos to RadianSin and RadianCos, and it works. It works without rounding off the decimal place, too.

    And, since I tested it, I can now say that I guarantee this will work, or your money back.
    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!

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

    Re: walkTo() void?

    Still doesn't work... When it has to go up, it goes down, and also it goes left when it has to go right(when it has to go up)... And I did tested your ffc script...

  8. #18
    Octorok CaRmAgE's Avatar
    Join Date
    Oct 2008
    Location
    Historia
    Age
    35
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    1,335
    Level
    12
    vBActivity - Bars
    Lv. Percent
    42.86%

    Re: walkTo() void?

    Hold on a minute...

    Shouldn't the code be...

    Code:
    import "advmath.zh"
    
    void moveTowards(ffc this, int x, int y, int speed) {
    	int angle = findAngle(this->X, this->Y, x, y);
    	float dx = RadianCos(angle) * speed;
    	float dy = RadianSin(angle) * speed;
    	
    	this->X += dx;
    	this->Y += dy;
    }
    
    ffc script followLink {
    	void run() {
    		while(true) {
    			moveTowards(this, Link->X, Link->Y, 1);
    			Waitframe();
    		}
    	}
    }
    Changes I made are in bold.

  9. #19
    &&
    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,303
    Level
    26
    vBActivity - Bars
    Lv. Percent
    8.74%

    Re: walkTo() void?

    It doesn't matter which way round you use them.

  10. #20
    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.56%

    Re: walkTo() void?

    Well, it does matter, but either way, I tested my script, and it worked. So... I dunno what to say. Make sure you're passing a positive speed... that's the only way I can think of to make it go backwards...
    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