A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: unusual collision detection

  1. #1
    file not found Captain_404's Avatar
    Join Date
    Apr 2006
    Posts
    457

    unusual collision detection

    Alright, I've got a game that I've been overhauling recently to make it wii friendly...

    original game:
    http://ian.janasnyder.com/valo.htm

    wii beta:
    http://ian.janasnyder.com/valoWii.htm

    Right now, my problem is collision detection, I've got a system for wii which I think is faster, but less accurate.

    The code I'm using for the wii version has shown profuse problems with collision detection, I'm not sure how you would run this kind of thing efficiently for this type of game, does anyone have any pointers?
    Code:
    function bleh() {
    	y3 = int(_ymouse/30);
    	x3 = int(_xmouse/30);
    	y1 = _ymouse;
    	x1 = _xmouse;
    	if (y3 > y2) {
    		n = y2;
    		n2 = y3;
    	} else {
    		n = y3;
    		n2 = y2;
    	}
    	yd = y1 - y0;
    	xd = x1 - x0;
    	m = yd/xd;
    	b = y3 - m*x3;
    	for (n; n <= n2; n++) {
    		n1 = (n - b)/m
    		q = _root["myMap"+game.currentMap][n][n1];
    		select = "t_"+n+"_"+n1;
    		atile = _root.tiles[_root.select]
    		if (drawn == 1) {
    			if (q == 1) {
    				atile.gotoAndStop(3);
    			}
    			if (q == 2) {
    				atile.gotoAndStop(6);
    			}
    			if (q == 3) {
    				atile.gotoAndStop(8);
    			}
    			if (q == 7) {
    				atile.gotoAndStop(11);
    			}
    			if (q == 8) {
    				atile.gotoAndStop(13);
    			}
    		}
    	}
    	y2 = int(_ymouse/30);
    	x2 = int(_xmouse/30);
    	y0 = _ymouse;
    	x0 = _xmouse;
    }
    I get the slope between the last mouse position and the current, and then run a for loop to see what tiles hit that line. Any suggestions?


    btw, the tile numerical values are:
    blue = 1
    red = 2
    green = 3
    enemy = 5
    yellow = 7
    purple = 8

  2. #2
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Dont you need to use integers for it to work? I mean, what if the m and b are something like 1.247545689745?

  3. #3
    file not found Captain_404's Avatar
    Join Date
    Apr 2006
    Posts
    457
    I'm not sure why non-int would be less accurate, I would think that sometimes you would need that odd slope that isn't a number of degrees divisible by 45, but somehow, integers do work better...(?)

    But I think I've found the major thing that was lacking from the script, I had a for loop that checked only for tiles on the _y, but if you drew a completely horizontal line, it wouldn't register anything at all. Of course, that would also play into effect when you have lines drawn that aren't totally vertical as well...it would always miss some tiles.

    So I added a loop that checks for the _x
    Code:
    function bleh() {
    	y3 = int(_ymouse/30);
    	x3 = int(_xmouse/30);
    	y1 = _ymouse;
    	x1 = _xmouse;
    	if (y3 > y2) {
    		n = y2;
    		n2 = y3;
    	} else {
    		n = y3;
    		n2 = y2;
    	}
    	yd = y1 - y0;
    	xd = x1 - x0;
    	m = int(yd/xd);
    	b = int(y3 - m*x3);
    	for (n; n <= n2; n++) {
    		n1 = (n - b)/m
    		q = _root["myMap"+game.currentMap][n][n1];
    		select = "t_"+n+"_"+n1;
    		atile = _root.tiles[_root.select]
    		if (drawn == 1) {
    			if (q == 1) {
    				atile.gotoAndStop(3);
    			}
    			if (q == 2) {
    				atile.gotoAndStop(6);
    			}
    			if (q == 3) {
    				atile.gotoAndStop(8);
    			}
    			if (q == 7) {
    				atile.gotoAndStop(11);
    			}
    			if (q == 8) {
    				atile.gotoAndStop(13);
    			}
    		}
    	}
    	if (x3 > x2) {
    		n = x2;
    		n2 = x3;
    	} else {
    		n = x3;
    		n2 = x2;
    	}
    	for (n; n <= n2; n++) {
    		n1 = m*n + b;
    		q = _root["myMap"+game.currentMap][n1][n];
    		select = "t_"+n1+"_"+n;
    		atile = _root.tiles[_root.select]
    		if (drawn == 1) {
    			if (q == 1) {
    				atile.gotoAndStop(3);
    			}
    			if (q == 2) {
    				atile.gotoAndStop(6);
    			}
    			if (q == 3) {
    				atile.gotoAndStop(8);
    			}
    			if (q == 7) {
    				atile.gotoAndStop(11);
    			}
    			if (q == 8) {
    				atile.gotoAndStop(13);
    			}
    		}
    	}
    	y2 = int(_ymouse/30);
    	x2 = int(_xmouse/30);
    	y0 = _ymouse;
    	x0 = _xmouse;
    }
    So, it basically works, but it still can't tell what the width of the line is and check for that...does anyone have any clever tricks?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center