Platformer question!


(Nate ) #1

Hey guys! I am back with another question! First of all I would like to say thank you so much for all of the input and help so far that I have received!

Okay so I will try to be brief with this one… Basically I have a world, a hero, and blocks. I have speed, gravity and friction all accounted for and working. I added a grass block for the ground and all hell broke loose… lol. Here is how I was handling just the ground prior to changing it out for the grass.

	if (collide("wall", x, y + 1))
		{
			ySpeed = 0;
			
			isJumping=false;
			if (Input.check(Key.SPACE))
			{
				ySpeed=-jumpPower;
				isJumping=true;
			}
		} 

I then had this one liner at the end of my conditionals:

moveBy(xSpeed, ySpeed, "wall");

This all worked like a charm. As soon as I tried adding some AND and OR’s pointing my game to the “grass” type it worked to an extent, but for some reason, my hero clips under the grass a few pixels. It is rather annoying and I am certain that it is because I am not giving it any moveBy information, but as soon as I do, the character runs SUPER fast. lol

So what do you guys think? How can I add the grass to the ground and still have it act like the walls aka blocks which simple just keep the hero from leaving the level and don’t allow the player to clip inside of them?

Thank you in advance! :smiley:


(Ultima2876) #2

If you post your current grass + wall collision code it’d possibly confirm a theory I have as to what might be the issue - I don’t want to suggest that fix as it might be wrong if you’re not doing what I think you are though.


(Nate ) #3

Okay well right now this is what my grass code looks like! I just added and OR to the wall collide code:

if (collide("wall", x, y + 1) || (collide("grass", x, y + 1)))
		{
			ySpeed = 0;
			
			isJumping=false;
			if (Input.check(Key.SPACE))
			{
				ySpeed=-jumpPower;
				isJumping=true;
			}
		} 
		
		
		
		
		else 
		{
			ySpeed+=gravity;
		}

As soon as I try to add grass to the moveBy function it freaks out… either my hero walks WAY too fast or he is able to run through the walls.


(Nate ) #4

Another thing I would like to do would be to add a character that just stands on the level, that you can walk up to and talk to. I have it all set up, except the hero is allowed to walk through the character. I have been messing with ySpeed and xSpeed and the hFriction and vFriction, but can’t get a combination to work.

What are your thoughts on that?


(Kevin Graham) #5

If they are both going to have the same type of collision, you could just set the collision type to solid, and then you only have to check once.


(Jacob Albano) #6

Try this instead:

moveBy(xSpeed, ySpeed, ["wall", "grass"]);

The move functions can optionally take an array of types that will all be checked as you move.


(Porter) #7

moveBy is definitely the way to go for platformers. This is a very old demo, but I wrote this in AS3 using FlashPunk, with moveBy.


(Nate ) #8

Jacob sending the moveBy function an array was just what I needed to do! That was my first thought but I was simply typing it wrong D: Also Porter, that looks great! May I have access to the source?

Thanks guys!


(Porter) #9

The source for that is super messy, and not really a framework, but more of a boiler plate. I’m working on re-writing it now, to include proper movement for ice (acceleration is wrong), better ladder movement, and an overall updated feel. I’ll post about it more once I’m done, but I could share the source of that when I am.


(Nate ) #10

Okay sounds good! No rush I was just curious as to if it was done and clean and I would be able to use it for the next hurdle I get stuck with!

What I have developed so far (a lot with the help of you fellow FlashPunkians) yes I just made that up lol… is pretty legit but I am certain I will come across more hurdles, sooner than later… lol