Angle joint problem

Mar 23, 2009 at 12:38 PM
Edited Mar 23, 2009 at 12:41 PM

I have been playing around with the tool and I got to say it's impressive, good work.

I'm trying to make a simple car but I'm having difficulties with the suspension. This is what I got:

As you can see, the suspension (which is the little rectangle on the left) doesn't work properly when I execute it.

This is what I'm trying to do :
In blend
And the application freeze which tells me I'm doing something really wrong.

Here is the code of the first exemple, it's just the body with one suspension:

<UserControlxmlns=""xmlns:x=""xmlns:d=""xmlns:mc=""mc:Ignorable="d"x:Class="TestBuggy.buggy"Height="70" Width="120" xmlns:Spritehand_FarseerHelper="clr-namespace:Spritehand.FarseerHelper;assembly=Spritehand.FarseerHelper">
<Canvas x:Name="LayoutRoot" Height="70" Width="120">
<Rectangle x:Name="buggybody" Height="35" Width="35" Fill="#FFFFFFFF" Stroke="#FF000000" Canvas.Left="40"/>
<Rectangle x:Name="rearSuspension" Height="10" Width="40" Fill="#FFFFFFFF" Stroke="#FF000000" Canvas.Left="15" Canvas.Top="35" RenderTransformOrigin="0.5,0.5" >
<RotateTransform Angle="-45"/>
<Spritehand_FarseerHelper:PhysicsJoint x:Name="backBodyJoint" BodyOne="rearSuspension" BodyTwo="buggybody" CollisionGroup="2" Canvas.Top="20" Canvas.Left="35"AngleSpringEnabled="True" AngleSpringDampningConstant="1000" AngleSpringConstant="1000" />

<UserControl x:Class="TestBuggy.Page"
xmlns=""xmlns:x=""Width="1000" Height="480" xmlns:Spritehand_FarseerHelper="clr-namespace:Spritehand.FarseerHelper;assembly=Spritehand.FarseerHelper" xmlns: TestBuggy ="clr-namespace: TestBuggy">
<Canvas x:Name="LayoutRoot">
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"><GradientStop Color="#FF000000"/>
<GradientStop Color="#FF0036BB" Offset="1"/>
<Spritehand_FarseerHelper:PhysicsController Height="18" Width="17" Canvas.Left="314" Canvas.Top="33" DebugMode="True" MousePickEnabled="True" AutoAddCanvasObjects="True" x:Name="PhysicsController1"/>
<Spritehand_FarseerHelper:PhysicsStaticHolder Height="37" Width="30" Canvas.Left="183" Canvas.Top="395" Body="ground" /><Rectangle x:Name="ground" Width="204" Height="20" Canvas.Top="395" Canvas.Left="114" Fill="#FF000000"/>
< TestBuggy:buggy x:Name="myBuggy" Height="70" Width="120" Canvas.Left="114" Canvas.Top="207"/>

Any idea ?

Thank you 
Mar 23, 2009 at 12:46 PM
Edited Aug 18, 2009 at 11:55 AM

UPDATE 8/18/2009: If you have any elements that have Transforms (Rotate, Scale, etc) and it is causing their Boundary Detection to be incorrect, you can solve this by Grouping the elements into a Canvas. Select the elements in Blend and select Group Into/Canvas. Then use the new Canvas as your Physics element instead of the original (now child) elements).


Hi David,

This is a bad limitation I know, but you can't have Transforms such as RotateTransform on objects that become Physics objects. The reason for this is that the Physics Library applies its own transforms for rotation, and when it does boundary detection, your orignal transforms won't be there.

So... try removing the RotateTransform from your rearSuspension Rectangle and see if that helps. I think that if you select "Object/Path/Convert to Path inside Expression Blend, it will keep that rotate angle for you and translate to a Path (I "think" anyway!)

Mar 23, 2009 at 1:27 PM
Ahh I see, I'll try to convert it to a path when I get back home later and see how that works. 
Worst case scenario, I'll use two rectangles to create a 90 degrees angle, that should give me a similar result.

Thank you for your help Andy
Mar 23, 2009 at 11:16 PM
Alright, you cannot simply ask blend to convert it into a path. 
The problem is blend will then make a path for an horizontal rectangle and then use a rotation transform on it. The result is the same as before.

So to make it works I had to draw the suspension by hand using the pen tool and then it works fine.

Now I'm trying to connect the suspension the a wheel. Do you have any tips on positioning the joint right in the middle of the wheel ?
I tried just by looking at the joint icon and the wheel but I always end up with a "locomotive" effect.

Also, my wheel are made of one ellipse, I have the impression that the helpers transform it into a polygon witch gives a "bumpy" effect when it roll, it's not smooth.. 
Any way to create a real circle ?

Thank you

Mar 24, 2009 at 12:18 AM
When you draw the joint control on the canvas, you should see a little circle icon with a line through it. The center of that circle is where the joint should be created. Make sure you set the CollisionGroup property on the Joint.

Boundaries are determined using an algorithm to trace the path around the UI Element, so they may not be completely smooth.  The reason we need to do this is because the Physics Helper doesn't include Ellipse calculations and Silverlight 2 does not support getting the vector geometry from a Path object in code.
You can add DebugMode="True" to the PhysicsController so that you can see how the boundary was determined.

You could create a Circle geometry "manually" through code if you want. In the Intitialized event of the PhysicsController you could add Geometries and Bodies using the "standard" Farseer class libraries instead of relying on the Physics Helper.
Mar 24, 2009 at 12:41 AM
Edited Mar 24, 2009 at 12:41 AM
The problem I had with the little circle icon is that the line doens't appear inside the circle but only on the edges so it's a bit of guesswork to place it exactly at the right place.
I believe something like a little dot right in the middle of the icon would greatly help.

Anyway, good tips about adding geometries manually, I'll play with that idea.