How to use a Path primitive in FPE 3.2

Topics: Developer Forum, Project Management Forum, User Forum
Jan 3, 2011 at 9:37 AM
Edited Jan 3, 2011 at 2:20 PM

Hi all,

I'm totally new to FPE and since i started to learn it so many changes were made to the engine, so most of the examples that i found on the web are now too old for work.

My purpose is to have a 2D roadmap made using a primitive path polygon in GLEED2D. Once, the way for working on that was to transform every single vertice/line of the path in a body/geom object and attach it to a phisic simulator.

Actually, there's no more phisicsSimulator nor the Geom. I must use the World instead a PS and a Shape instead a Geom, right?

My deal is to decect collision between the ground path that i draw and my main character. The ground path have up and down hills and character must follow them while walking.

I suppose that i have to create a body/shape for my character, attaching it to my World, and it's ok so far.

I load the xml file with my path data from gleed2D and i can scan sequentially every item in every layer i created.

For each item of my level (every item is a path segment) i have to create the relative body/shape and attach it to my world? I must use both World.AddBody and World.BodyList.Add?

Or i must use the Path/Pathmanager class? And how can i check collision between my char shape and the path itself?

There's no samples in simpleSample 3.2 that uses Path, or i'm wrong?

If i have my char shape and my item list shape, how can i detect what shapes are very next/near to my character shape to detect collisions? I need to scan them one by one using position coordinates, fixture checking or something else? The OnBroadphaseCollision fires automatically between the fixture of character body and the path ground body?

Thank you. Greetings!

Jan 3, 2011 at 3:19 PM
Edited Jan 3, 2011 at 3:21 PM

Could i use something like the following?

- I create a class that creates a world and a path for the current level;

- I load the xml file and scan every item

- Every item in deserialization has a vector, either if is a polygon or a path

- If it's a path, i simply add the vector of the item in the path object that i created in the class

- If it's a polygon, i create a new body/shape in the class for the polygon, passing the vector and so on

In this way can i replicate the physical struct of my level?

And what for the collisions? Once i defined all the entities, if my Hero shape collides with the Path, what event is fired up?

 

I know i'm not a Farseer geek and my questions are maybe a little bit dumb, but for me it's a bottleneck, when i'll got these aspects i'll be more indipendent on my work. Thank you again!

Jan 4, 2011 at 10:08 AM

Sorry for keep on this request, but i got some new results day by day and i need to figure out how all this stuff works.

As i said, now i have a Farseer Path object that i used to add an array of vector2 points on it, and now i have a complete path to walk on.

My purpose is still to understand how i can manage collision between this path and my character shape object.

It's something like the Tank demos that i saw here and on the web, but having not the source code of it i can't get a detailed procedure, and simplesamples 3.2 does NOT contain a path example. Other code samples i found were refered to previous Farseer versions.

Will be the OnCollision event raised automatically when my shape object will collide the path?

Also, i'm trying to display my path using the debugViewer, but the RenderDebugData fails on receiving the matrix ref view with a nullreference exception.

Thanks in advance for who wants to help me :)

Developer
Jan 4, 2011 at 11:27 AM

I'm not sure what exactly you are trying to achieve. I think you could just use edge or loop shapes. If your editor already exports your level geometry via polygons you just have to pass them to the loop factory for example. It would help if you could further describe what exactly Gleed exports, cause I have no idea what you mean by path polygon. Is it a polygon, or splines, or something else...

Collisions are handled automatically by Farseer, thats the whole point of using a physics engine. There are several ways of being notified about a collision so that you can respond to it. One being the OnCollision delegate you mentioned. You can find several examples on how to use those delegates in the testbed and here on the forums.

May I suggest though that you try to get the basics of Farseer first before you try to play around with the advanced stuff. A good place to start would be the Box2D Manual:

http://www.box2d.org/manual.html

It explains the basics of creating and adding bodys with shapes attached to them via fixtures pretty well. I may be wrong, but I don't think you need to bother with the path class at all for accomplishing your goal of having a character moving on a landscape. A path at least is not something you can directly add to the engine but just a tool to help you generate physical objects from some base points.

Jan 4, 2011 at 1:01 PM

Basically, Gleed exports an xml serialized with nodes and tags for every object you draw with it.

In case of Path, he exports a serialized object with a x,y coordinate for every point that defines the path. I use these coordinates to define an Vector2 array to pass step-by-step to the Path (Path.Add).

I used a farseer path because the char must walk not on a polygonal platform (like a rectangle) but on a ground composed by many lines in order to form an irregular terrain (like the Tank demo, or just think about the first level of Ghouls n Ghosts). I'll check the Edge and Loop to see if i can use them. Or maybe i must use a polygonal shape, but it must to be closed, so i'll try to define a polygonal with vertices taken from the vector2 array but with 2 more vertices to unite the end point with the start point.

(a)_/\____/\__(b)     <--- this is my path

|________|      <---- this is the 2-vertices that i could add (the ground under the path) for obtain a closed polygon. The vertices unites (a) with (b).

I hope that my explication is clear...

Thank You!

Developer
Jan 4, 2011 at 1:51 PM
Kappeijin wrote:

Basically, Gleed exports an xml serialized with nodes and tags for every object you draw with it.

In case of Path, he exports a serialized object with a x,y coordinate for every point that defines the path. I use these coordinates to define an Vector2 array to pass step-by-step to the Path (Path.Add).

Ok forget about Farseers path class. It has nothing to do with the kind of path you have in mind. As I already said please take a look at the Box2D manual first to understand the basics of shapes, bodies and fixtures.

I used a farseer path because the char must walk not on a polygonal platform (like a rectangle) but on a ground composed by many lines in order to form an irregular terrain (like the Tank demo, or just think about the first level of Ghouls n Ghosts). I'll check the Edge and Loop to see if i can use them.

Your character will always walk on "polygonal platforms" cause that is the only thing Farseer knows (except from circles). Edge shapes are in principal just a closed polygon comprising of two points. Loop shapes are a (closed) list of concatenated edge shapes.

Or maybe i must use a polygonal shape, but it must to be closed, so i'll try to define a polygonal with vertices taken from the vector2 array but with 2 more vertices to unite the end point with the start point.

(a)_/\____/\__(b)     <--- this is my path

|________|      <---- this is the 2-vertices that i could add (the ground under the path) for obtain a closed polygon. The vertices unites (a) with (b).

Three "easy" ways to do this:

1) Recreate your path with a series of edge shapes. Exactly as it is represented within Gleed.

2) Create the closed polygon you describe here and convert that to a loop shape. This should be the easiest solution as there exist a factory which can create it from a vertices object.

3) Create several polygon shapes that represent your landscape. Farseer can only handle convex polygons with a maximum of 8 points though. So you need to decompose your landscape polygon into those. Farseer has tools for that, but its not worth the hassle. You should get better results with solution 2)

Be warned though that you will probably run into problems, with your character getting stuck at seams within your landscape. See: 13. 2. http://www.box2d.org/manual.html#_Toc258082979

There are several threads here, which address these problems and suggest setups for characters in such an environment (if you are going for something like Ghouls 'n Ghosts)