Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have seen this game

Fancy Pants 2 . And the thing I noticed apart from the physics and beautiful animations is that the character is moving along slopes , even curved slopes. I have little experience in Box2d, but this concept of curved slopes is new to me. It would be a great help to me If somebody enlightened me on this concept and its implementation. Even If the implementation is not in box2d, it is welcome.

share|improve this question
2  
Metanet, the guys who did N (which is in Flash) have a tutorial on how they did collisions that covers how they calculate curves: metanetsoftware.com/technique/tutorialA.html –  CodexArcanum Oct 13 '10 at 15:45

2 Answers 2

up vote 5 down vote accepted

How do you get curves in Box2D?

In the unreleased version of Box2D, there are two new shape types, b2LoopShape and b2EdgeShape, which let you build curves out of a sequence of line segments.

In the released version, you can use multiple small boxes set at angles to get a similar effect, but bodies have a tendency to do unstable and unexpected things near connection points. So I'd recommend using the unreleased version.

How can a character fall down the curve?

Make the character a wheel! My question about platformer physics has some discussion on this, but the basic idea is to mount your character's body on a rotating wheel, and move by applying rotational force to the wheel. Even though (actually, because) the wheel has friction, the downward force from gravity will cause it to rotate down slopes - like a real wheel. By changing the revolute joint's motor parameters, you can make it resist rotation as much as is necessary to avoid it rolling down small inclines.

share|improve this answer
    
I agree with you, in using b2LoopShape I could create a slope as my desire. But, on following the link you posted; The problem is, it doesn't lead to a flash port of box2d just a c++ version. 1.) Do you have any suggestions for that? or 2.)Do you know of any other physics engine for flash which allows creation of curved slopes? –  Vishnu Oct 11 '10 at 4:26
    
I don't think the Flash port of Box2D is up-to-date with the new joint/shape types. I have no idea what physics engines are available for Flash other than Box2D. –  user744 Oct 11 '10 at 8:33
    
@ Joe : If I ask you, If it would be feasible if I tried writing an AS class for b2LoopShape?So that I could incorporate it into the Box2d Flash api. Where would I have to start heading.? Any clue? –  Vishnu Oct 11 '10 at 8:57

Fancy Pants was made in Flash, and Flash has a specific method called 'hitTest' which allows you to test a pixel (in this case, he probably does 2-3 pixel hitTests along the bottom of the Fancy Pants character) against whatever is drawn within a designated movieclip object. It can be a bit tricky to get it feeling right, but this built-in function is why so many Flash games have collisions with curved slopes. The process is much more complicated for most other engines, and usually has to be done manually, but there are a few different methods.

The method I'm most familiar with is if your engine is tile-based (think Sonic the Hedgehog), the tiles designated as curved could each have a formula which determines the 'Y' collision position based on the character's current 'X' position on that tile. You would have to determine the formula based on how steep of a slope and how curved you're looking for. You could use a graphing calculator or graphing program to experiment with the formulas. You can have multiple tiles with different curves and formulas associated with them this way.

share|improve this answer
    
Sonic does not have a curve formula for the tiles. It uses a 2d height-map for each pixel. –  AttackingHobo Oct 8 '10 at 16:18
    
@AttackingHobo: Can you tell me what is 2dheight map for each pixel or can you point me to a place where I can use that for in my flash games ? –  Vishnu Oct 11 '10 at 4:28
2  
info.sonicretro.org/Sonic_Physics_Guide Take a look at this. I don't know if this will help you if you use box 2d. You might have to roll your own physics engine. –  AttackingHobo Oct 11 '10 at 5:34
    
@Attacking Hobo : Is there any advantage or possibility in "doing" curved slopes If i try making an AS 3.0 class that allows loops in the box2d api? –  Vishnu Oct 11 '10 at 8:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.