collision

Sep 16, 2008 at 4:05 AM
hi, how i can make collision between shapes in silverlight? or its support only rectangles and circles?
Coordinator
Sep 16, 2008 at 7:24 AM
Create 2 bodies and 2 geoms. Put each geom into different collision groups and make them bump into each other. Thats all :)

Have a look at the Demo 2 from the samples. They demonstrate it very well.
Sep 16, 2008 at 10:38 AM
When i create rectangle using Vertices.CreateRectangle collisions works, but when i triangle they stop working. Its a bug or i do something wrong?
Coordinator
Sep 16, 2008 at 10:45 AM
Create a rectangle like this:

Note that I don't have access to any code or tools right now.

Vertices vertices = new Vertices();
vertices.Add(-5,-5);
vertices.Add(0,5);
vertices.Add(5,-5);

Geom geom = GeomFactory.Instance.CreatePolygonGeom(physicssimulator, vertices..... so on)
geom.CollisionGroup = 1;

Geom geom2 = GeomFactory.Instance.CreateRectangleGeom(physicssimulator, ..... so on)
geom2.CollisionGroup = 2; // Geoms in different groups collide with each other.
Sep 20, 2008 at 6:13 PM
I made 2 those triangles but they does not collide. Some times they collide but its very buggy.I dont need create Body objects?
Coordinator
Sep 20, 2008 at 8:26 PM
You should also create bodies.

Can you pack up the project that you have problems with and send it to me? (or send it to an upload service.)
Sep 22, 2008 at 6:11 AM
Edited Sep 22, 2008 at 6:12 AM

I posted source code before in this topic http://www.codeplex.com/FarseerPhysics/Thread/View.aspx?ThreadId=35599, but nobody replied=( 

source code:  http://rapidshare.com/files/144962042/SilverlightGame.zip.html

Coordinator
Sep 22, 2008 at 12:49 PM
I going to take a look at it now. I must have overlooked your thread from before, sorry about that.
Coordinator
Sep 22, 2008 at 1:02 PM
Edited Sep 22, 2008 at 1:05 PM
Oh, okay. Now I see your problem.

The shapes are entering each other, this can be prevented by tweaking 2 factors:

1. Collision Grid Size
2. SubDiviceEdge


The first one is size of the cells in the grid that Farseer uses for collision detection. The smaller the size, the better accuracy. But a smaller grid cell size altso equals more computation when creating the grid. You try setting the gridcellsize in the GeomFactory.Instance.CreatePolygonGeom() method's parameter to a smaller size than the default.

The second solution is to insert more vectors/points/polygons in the corners. You can use the Vertices.SubDivideEdges(float) to insert more polygons on the edges.

Try out each of them and see what happens. There are also some other discussions with the same "problem" that you might want to take a look at.

EDIT
You might want to take a look at this coding standard from Lance Hunt (Microsoft). You may have your own standard, but following a real coding standard takes care of a lot of naming issues and conflicts.

I also saw that you have Resharper 4.1 installed, try installing the Agent Smith plugin for Resharper (or CodeStyle) to keep track of inconsistent code style. (remember to configure Agent Smith to conform with the Lance Hunt coding standard)
Sep 23, 2008 at 4:00 PM

thanks for agent smith plugin

collision grid size does not effect , and with SubDiviceEdge collision works even worse =(