What would be the best way to simulate "ramp physics" using the PMO? For example, a skateboard or ball is moving up a straight or curved ramp at high speeds. The faster it's moving, the higher up in the air it goes once it hits the top of the ramp.
Better yet, here's a video showing what I'm trying to do. You'll see how the object moves around ramps in the very beginning.
Well for one, my player isn't just a ball -.-; I'm not looking for a full blown physics engine, just something that can work around ramps. Something tells me Sonic didn't use a physics engine :X
n/a
Assault Andy Administrator
I make other people create vaporware
Registered 29/07/2002
Points 5686
1st June, 2010 at 08:42:10 -
Sonic does use a 'physics' engine, just not a modern open source one like Box2D. Every platformer you make has some sort of physics engine. If you want to replicate the movement in that video it would be quite simple with something like the Box2D extension. The only problem would be getting the polygons on the map in the right spots, though you could just use simple triangle slopes. There are too many curves in that video to get something accurate using the PMO.
Alternatively, if you want to use the PMO and simplistic ramp physics, you could have a detector on the left and right of your player near their feet, and when one of them is overlapping an obstacle and the other isn't then you know that you must be on a slope (provided that there isn't also a full wall). You could then subtract an appropriate amount of X Velocity to move the player down the slope.
Sorry I could have been a bit more specific.. All I'm trying to do is get my player to fly up a slope/ramp once it gets past the top. It already moves around slopes/ramps fine, it just doesn't fly up into the air when going up one quickly. I've got an idea though..
n/a
Assault Andy Administrator
I make other people create vaporware
Registered 29/07/2002
Points 5686
1st June, 2010 at 13:23:22 -
If you want to do a dodgey, then just put 'slope detectors' at the top of all the slopes. Make 2 types - one for left and one for right. Then you make it so if you are overlapping one and facing the right direction and moving a certain speed, use a PMO action to make the player jump.
Use the X-velocity that the object is moving at when it collides with the ramp, and then use that number to gradually increase Y-velocity and decrease X-velocity. Should work if you get the numbers right!
Best of luck to you!
Originally Posted by Assault Andy If you want to do a dodgey, then just put 'slope detectors' at the top of all the slopes. Make 2 types - one for left and one for right. Then you make it so if you are overlapping one and facing the right direction and moving a certain speed, use a PMO action to make the player jump.
This is kinda what I used for "Emo Skate Phonics", and you see how that went..
Basically, you want the player to maintain their speed as they move in a direction. You'll need to use vectors to do this. Wikipedia will describe them better if you don't know what they are. http://en.wikipedia.org/wiki/Euclidean_vector
Wait a moment, I'll whip up a few images real quick to explain this.
Let's say that you have a player, who moves left or right at a speed of 4 pixels per frame:
They've now moved 4 pixels to the right between each frame, and are going to keep moving right:
On this frame, they hit this 45° ramp halfway through their steps. I'd venture a guess to say that 99% of the movement engines we see do this: The player moves forward two pixels, then goes up one, then right one, then up one, then right one.
A little more obvious in this frame, the player keeps going up one, right one, stair-stepping until they have moved right 4 times:
That last image illustrates why you need to use a vector movement. The player is moving a total of 8 pixels (up+right) in order to move 4 units to the right. With a vector movement, instead of just moving the player left/right 4 pixels, you would be moving them in a direction by 4 pixels.
Let's convert that stair-stepping into a proper vector. The player's x change is 4, their y change is 4. We've got two sides of a right triangle, so all we need to do is find the length of the hypotenuse, using good ol' Pythagorean's theorem: a^2 + b^2 = c^2
• c^2 = 4^2 + 4^2
• c = 5.66
This means that by stair-stepping, the player's vector is 45° by 5.66 pixels. The player should be moving at 4 pixels, so now we have to figure out how to get a hypotenuse of 4. The answer:
On a 45° ramp, the player needs to move up/right 2.82 pixels in order to move diagonally 4 pixels.
So you've adjusted for the player's speed to be correct when they go up a ramp. Now you need to actually implement this into your engine. It's really simple, depending on how you have your engine set up. All you need to do is have the player's horizontal and vertical position be changed at the same time. For example, engines that move the player based on alterable values should be setting the player's x and y values at the same time when they move, regardless if they're jumping or running.
If you implement this correctly, then the player should go flying off of a ramp automatically without requiring any extra coding.
I missed the part about how you detect that it's a ramp
Disclaimer: Any sarcasm in my posts will not be mentioned as that would ruin the purpose. It is assumed that the reader is intelligent enough to tell the difference between what is sarcasm and what is not.