Computer Science Canada Platform Help Needed |
Author: | pttptppt [ Mon Mar 06, 2017 10:20 pm ] | ||
Post subject: | Platform Help Needed | ||
What is it you are trying to achieve? I am making a platform game (think Mario). I want the player to be able to jump from platform to platform. What is the problem you are having? When the player is underneath a platform, he automatically jumps on top of the platform even if it's too high. I dont want that. Describe what you have tried to solve this problem I've tried making it so if cy > InvisiPlatform2... That way only when he can actually jump onto that platform, he does. Problem is that didn't work Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <Answer Here>
Please specify what version of Turing you are using Latest |
Author: | pttptppt [ Tue Mar 07, 2017 7:13 pm ] |
Post subject: | RE:Platform Help Needed |
Anyone??? PLease |
Author: | Insectoid [ Thu Mar 09, 2017 12:36 pm ] |
Post subject: | RE:Platform Help Needed |
You're on the right track. What is the condition for jumping on a platform? Can you jump 'through' platforms from underneath like mario? Or do you bounce off? It helps to say exactly what you want to happen in plain old english before turning it into code. Think about all the different cases that might come up and try to fit them into a generalized solution. There's lots of different ways so I'll just give you a few hints and let you figure it out from there. A platform is just usually just a rectangle. Rectangular collision is pretty simple, right? But really, the platform is only the top line of the rectangle- you can't land on the bottom line, that just wouldn't make sense! If you hit the bottom line or the sides, you don't land, you just bounce off! So how do you know if you hit the top line? There's a few ways. You can use ordinary line collision, which is identical to rectangular collision where y1 = y2. You could check the player's velocity- you can't hit the top line if you're going up, and you can't hit the bottom line if you're going down. Probably a combination of the two is best. You may run into a problem where characters sometimes go right through the platform without even noticing- this may be due to high speed. If the platform is 10 pixels thick, and the player moves 20 pixels per frame, the collision may happen between frames and therefore not register. There's a number of ways to solve this too, but I wouldn't bother unless it actually affects your game. |
Author: | pttptppt [ Thu Mar 09, 2017 3:32 pm ] |
Post subject: | Re: RE:Platform Help Needed |
Insectoid @ Thu Mar 09, 2017 12:36 pm wrote: You're on the right track. What is the condition for jumping on a platform? Can you jump 'through' platforms from underneath like mario? Or do you bounce off?
It helps to say exactly what you want to happen in plain old english before turning it into code. Think about all the different cases that might come up and try to fit them into a generalized solution. There's lots of different ways so I'll just give you a few hints and let you figure it out from there. A platform is just usually just a rectangle. Rectangular collision is pretty simple, right? But really, the platform is only the top line of the rectangle- you can't land on the bottom line, that just wouldn't make sense! If you hit the bottom line or the sides, you don't land, you just bounce off! So how do you know if you hit the top line? There's a few ways. You can use ordinary line collision, which is identical to rectangular collision where y1 = y2. You could check the player's velocity- you can't hit the top line if you're going up, and you can't hit the bottom line if you're going down. Probably a combination of the two is best. You may run into a problem where characters sometimes go right through the platform without even noticing- this may be due to high speed. If the platform is 10 pixels thick, and the player moves 20 pixels per frame, the collision may happen between frames and therefore not register. There's a number of ways to solve this too, but I wouldn't bother unless it actually affects your game. I get what you're saying but it just isn't working. Ive tried putting different conditions but the end result is always simply i can't jump when im on a platform and if im under a platform, independant of the height of the platform, it'll jump to directly to the platform. It'd be helpful if you could look at my code and provide examples of what youre saying. For example, youre telling me to use line collision but i already am.. Please help soon because exam period is coming so i wont be able to code during that time |
Author: | Insectoid [ Fri Mar 10, 2017 10:40 am ] | ||
Post subject: | RE:Platform Help Needed | ||
Let's translate this code to english to see what it's actually doing:
This says "If we are in the air, lower than the platform, and between the sides of the platform then put us on top of the platform" That is a literal translation of that line of code to english. That is what this code does. Is that what you want the code to do? Can you think of a situation that satisfies this condition where we do not want to be moved to the top of the platform? Can you re-word that english statement to more accurately reflect the behavior you want? Here's another small hint- What is the ground? For you, it's just a number GROUND_HEIGHT, and needs all its own special code to handle. What if you made the ground just a platform, like everything else? That way, you have to write exactly zero code to handle the ground. You never have to check it. Just make a platform at the bottom of the screen and your existing platform code will automatically handle it. |
Author: | pttptppt [ Fri Mar 10, 2017 10:56 am ] | ||
Post subject: | Re: RE:Platform Help Needed | ||
Insectoid @ Fri Mar 10, 2017 10:40 am wrote: Let's translate this code to english to see what it's actually doing:
This says "If we are in the air, lower than the platform, and between the sides of the platform then put us on top of the platform" That is a literal translation of that line of code to english. That is what this code does. Is that what you want the code to do? Can you think of a situation that satisfies this condition where we do not want to be moved to the top of the platform? Can you re-word that english statement to more accurately reflect the behavior you want? Here's another small hint- What is the ground? For you, it's just a number GROUND_HEIGHT, and needs all its own special code to handle. What if you made the ground just a platform, like everything else? That way, you have to write exactly zero code to handle the ground. You never have to check it. Just make a platform at the bottom of the screen and your existing platform code will automatically handle it. Thanks for the reply. Like i said in my original post when i said what i tried to change, i changed that line to be cy > InvisiPlatformy2. However, when I tried that, the program ended up being even more broken. Can you try running that to see what i mean? |
Author: | pttptppt [ Fri Mar 10, 2017 4:02 pm ] | ||
Post subject: | RE:Platform Help Needed | ||
Here I've changed the code a bit. Now the problems are: 1. i can only stay on the platform if i have jumped from anywhere but under the platform. In other words, i can only stay on platform if my starting x is not= the the x of the platform 2. If i do manage to jump on the platform, if i jump again ill sink through the platform. This is probably for the same reason that problem #1 is happening My code:
|