The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 14 of 14

Thread: Platformer Game - Collision not working for some reason

  1. #1

    Platformer Game - Collision not working for some reason

    Okay.. I'm not really sure what happened to the other thread there. Some database error.

    Anywho, what I said, was that I'm having a minor issue w/ a hittest i'm using in a script for a small platformer game I'm helping a friend with. The background is all one movieclip and I want the hero movie clip to recognize it as the ground. However, when the hero jumps, he commits suicide by jumping through the floor. I've looked at my code repeatedly and it looks fine, so I'm not really sure what the problem is, but I'm sure its something stupid. I'm getting rather frustrated tho. If anyone wouldn't mind taking a moment to look at it and see if they can see what I'm missing, it would be much appreciated.

    http://www.jlcreationsonline.com/syn...platformer.zip

    The part of the code that is having issues is commented for easy finding. Thanks again.
    Last edited by jaelle; December 28th, 2004 at 04:48 PM.

  2. #2
    off topic
    am sorry but that was funny
    he commits suicide by jumping through the floor
    by the way why not post the code that way people can actually look at the code and maybe be able to pinpoint the problem

  3. #3
    Hi,

    I can't view the game you made (it's not MX), but I did write two tutorials on how to create platform games; Just search the first page of the forum.

    peace
    .: Let your Imagination Soar! :. -JoMan.
    : Kirupa Nintendo Cult Member 31 :

  4. #4
    Yep joMan, I looked through your tutorials and incorporated them some, however, the problem I think I'm having is probably a a stupid error that happened from too much staring at code and now I'm blind to it , I'm not really sure what else it can be.

    Here is the swf: http://www.jlcreationsonline.com/syn...ame/final.html Notice how when you jump (up-arrow), he doesn't manage to ever hit the floor, but just keeps right on going.

    Here is all code if that helps. My goal is to make the "It will be a miracle if this shows up" appear, which would also set the velocity to zero and stop its speedy decent. For some reason it never evaluates the hitTest to true, and i'm not sure why, considering it goes right over the top. I considered that since it is going in increments of 10, the x,y coordinate might never come in contact w/ the thin line that makes the ground. However, i made it go in increments of 1 and it didn't help. If I change the hittest statement to "_root.game_mc.limit_mc.hitTest(hero.mc)", I get the "It will be a miracle if this shows up" to appear, but he never jumps. Any suggestions would be most appreciated.

    Code:
    import as.Enemy;
    import as.Hero;
    
    Enemies = [];
    hero = new as.Hero(game_mc.hero_mc);	
    right = 1;
    left = -1;
    initializeEnemies();
    initializeHero();
    game_mc.onEnterFrame = function() {
    	moveEnemies();
    	//****What is wrong here?****//	
    	if(!_root.game_mc.limit_mc.hitTest(hero.mc._x, hero.mc._y, true)) {
    		hero.mc._y -= hero.getYvelocity(); //value for hero jump
    	} else {
    		trace("It will be a miracle if this shows up");
    		hero.Yvelocity = 0;
    	}
    	//**************************//
    	hero.mc._x += hero.Xvelocity();  //value for horizontal velocity
    	
    	if (Key.isDown(Key.RIGHT)) {
    		if(Key.isDown(Key.DOWN)) {
    			duckmove(right);
    		} else if(Key.isDown(Key.UP)) {
    			jump(right);
    		} else {					  
    			run(right);
    		}
    	} else
    	if (Key.isDown(Key.LEFT)) {
    		if (Key.isDown(Key.DOWN)) {
    			duckmove(left);
    		} else if(Key.isDown(Key.UP)) {
    			jump(left);
    		} else {
    			run(left);
    		}
    	} else
    	if (Key.isDown(Key.DOWN)) {
    		if (Key.isDown(Key.RIGHT)) {
    			duckmove(right);
    		} else if (Key.isDown(Key.LEFT)) {
    			duckmove(left);
    		} else {
    			duck();
    		}
    	} else
    	if (Key.isDown(Key.UP)) {
    		if (Key.isDown(Key.RIGHT)) {
    			jump(right);
    		} else if (key.isDown(Key.LEFT)) {
    			jump(left);
    		} else {
    			jump();
    		}
    	} else {
    		stand();
    	}
    }
    
    function initializeEnemies() {
    	Enemies.push(new as.Enemy(game_mc.enemy01_mc, 55, 345));	
    	Enemies[0].mc.gotoAndStop("run_right");
    }
    function initializeHero() {
    	hero.mc.gotoAndStop("stand_right");
    }
    function moveEnemies() {
    	if (Enemies[0].mc._x >= Enemies[0].rightBoundary) {
    		Enemies[0].mc.gotoAndStop("run_left");
    		Enemies[0].dir*=-1;
    	}
    	if (Enemies[0].mc._x <= Enemies[0].leftBoundary) {
    		Enemies[0].mc.gotoAndStop("run_right");
    		Enemies[0].dir*=-1;
    	}
    	Enemies[0].mc._x += Enemies[0].speed * Enemies[0].dir;
    }
    function run(dir) {
    	if (dir == right) {
    		hero.mc.gotoAndStop("run_right");
    	}
    	if (dir == left) {
    		hero.mc.gotoAndStop("run_left");
    	}
    	hero.mc._x+=hero.speed*dir;
    	hero.dir = dir;
    }
    function duckmove(dir) {
    	if (dir == right) {
    		hero.mc.gotoAndStop("duckmove_right");
    	}
    	if (dir == left) {
    		hero.mc.gotoAndStop("duckmove_left");
    	}
    	hero.mc._x +=hero.speed*dir;
    	hero.dir = dir;
    }
    function duck() {
    	if (hero.dir == right) {
    		hero.mc.gotoAndStop("duck_right");
    	}
    	if (hero.dir == left) {
    		hero.mc.gotoAndStop("duck_left");
    	}
    }
    function jump(dir) {
    	if (!hero.jump) {
    		hero.Yvelocity = 10;
    	}
    	hero.Xvelocity = hero.speed*hero.dir;
    	hero.jump = true;
    	if (dir == right) {
    		hero.mc.gotoAndStop("jump_right");
    	} 
    	if (dir == left) {
    		hero.mc.gotoAndStop("jump_left");
    	}
    }
    function jump() {
    	if (!hero.jump) {
    		hero.Yvelocity = 20;
    	}
    	hero.jump = true;
    }
    function stand() {
    	if (hero.dir == right) {
    		hero.mc.gotoAndStop("stand_right");
    	} 
    	if (hero.dir == left) {
    		hero.mc.gotoAndStop("stand_left");
    	}
    }

  5. #5
    Hmm, I'm not sure what the problem is either...
    .: Let your Imagination Soar! :. -JoMan.
    : Kirupa Nintendo Cult Member 31 :

  6. #6
    I think that maybe the line is too thin, try it with a thicker line to see if that works...just a guess.

    EDIT: Oops just re-read you post.
    Last edited by gaming monkey; December 28th, 2004 at 11:33 AM.

  7. #7
    I've got no clue what you did wrong, but from what I see you've made it way too complicated for a platform game...just look at Joman's tutes about platform games and don't get so tangled up with the code

  8. #8
    I'm a masochist programmer tho, I thrive off of making things complicated

    But yea.. I probably will just have to write it over from scratch, since no one seems to know what the problem is.

  9. #9
    Quote Originally Posted by jaelle
    I'm a masochist programmer tho, I thrive off of making things complicated

    But yea.. I probably will just have to write it over from scratch, since no one seems to know what the problem is.
    Like you said though, it might be one of those small bugs that you can't find that drives you completely nuts .
    .: Let your Imagination Soar! :. -JoMan.
    : Kirupa Nintendo Cult Member 31 :

  10. #10
    Well completely rewriting the code should fix that! I'm going to go read through your tutorial a bit more closely now. Might as well go with the tried and tested way if trying to invent my own way fails.

  11. #11
    Quote Originally Posted by jaelle
    Well completely rewriting the code should fix that! I'm going to go read through your tutorial a bit more closely now. Might as well go with the tried and tested way if trying to invent my own way fails.
    But also, don't stop developing your own way in programming, It's a good thing to do, and it is a way that people will recognize you (next to the art you use).

    peace
    .: Let your Imagination Soar! :. -JoMan.
    : Kirupa Nintendo Cult Member 31 :

  12. #12

    Quote Originally Posted by joMan
    But also, don't stop developing your own way in programming, It's a good thing to do, and it is a way that people will recognize you (next to the art you use).

    peace
    that's true

  13. #13
    Oh, no worries, I won't copy it word for word. But I might borrow the concepts.

  14. #14
    Quote Originally Posted by jaelle
    Oh, no worries, I won't copy it word for word. But I might borrow the concepts.
    That's a good thing to do .

    peace
    .: Let your Imagination Soar! :. -JoMan.
    : Kirupa Nintendo Cult Member 31 :

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
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012