ground collision problem (new user)

Apr 23, 2011 at 9:31 PM

Hello , I'm a new user with Physics Helper . After watching your tutorial video , I've tried to create my first Car App.

When I created the static Path for the ground , there seemed to be a problem with the boundy collision. it seems not have followed the path surface , but  the rectangle that encapsulates the whole path.

In you video , when you used the pen in Blend to create a path for the ground a ran the application , it seemed ok. why do you think is that?

I'm adding my Xaml code ,

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"  
    xmlns:pb="clr-namespace:Spritehand.PhysicsBehaviors;assembly=Spritehand.PhysicsBehaviors"
    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" x:Class="startingwothfarseer1.firstCar"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
   
    <Canvas x:Name="LayoutRoot" Background="#FF602323" HorizontalAlignment="Left" Width="600" Height="400">
        <i:Interaction.Behaviors>
            <pb:PhysicsControllerBehavior MousePickEnabled="True" DebugMode="True"/>
        </i:Interaction.Behaviors>
        <Ellipse x:Name="backwheel" Fill="#FF5E17A9" Height="24" Canvas.Left="192" Stroke="Black" Canvas.Top="104" Width="24">
            <i:Interaction.Triggers>
                <ei:KeyTrigger Key="Left">
                    <pb:PhysicsApplyTorqueBehavior TorqueValue="-1"/>
                </ei:KeyTrigger>
                <ei:KeyTrigger Key="Right">
                    <pb:PhysicsApplyTorqueBehavior TorqueValue="1"/>
                </ei:KeyTrigger>
            </i:Interaction.Triggers>
            <i:Interaction.Behaviors>
                <pb:PhysicsObjectBehavior RestitutionCoefficient="0.5"/>
            </i:Interaction.Behaviors>
        </Ellipse>
        <Ellipse x:Name="frontwhell" Fill="#FF5E17A9" Height="24" Canvas.Left="248" Stroke="Black" Canvas.Top="104" Width="24">
            <i:Interaction.Behaviors>
                <pb:PhysicsObjectBehavior RestitutionCoefficient="0.5" />
            </i:Interaction.Behaviors>
        </Ellipse>
        <Rectangle x:Name="carbody" Fill="#FFE97A0E" Height="24" Canvas.Left="176" Stroke="Black" Canvas.Top="80" Width="112">
            <i:Interaction.Behaviors>
                <pb:PhysicsObjectBehavior/>
            </i:Interaction.Behaviors>
        </Rectangle>
        <Ellipse Fill="#FFA91789" Height="5" Canvas.Left="201" Stroke="Black" Canvas.Top="113" Width="5">
            <i:Interaction.Behaviors>
                <pb:PhysicsJointBehavior BodyOne="backwheel" BodyTwo="carbody" AngleSpringDampningConstant="10" CollisionGroup="1"/>
            </i:Interaction.Behaviors>
        </Ellipse>
        <Ellipse Fill="#FFA91789" Height="5" Canvas.Left="258" Stroke="Black" Canvas.Top="113" Width="5">
            <i:Interaction.Behaviors>
                <pb:PhysicsJointBehavior BodyOne="frontwhell" BodyTwo="carbody" CollisionGroup="1"/>
            </i:Interaction.Behaviors>
        </Ellipse>
    <Path x:Name="rock" Data="M350.5,40 L328.5,63 L343.5,92 L378.5,89 L378.5,45 z" Fill="#FF612F0A" Height="53" Canvas.Left="328" Stretch="Fill" Stroke="Black" Canvas.Top="39.5" UseLayoutRounding="False" Width="51">
        <i:Interaction.Behaviors>
            <pb:PhysicsObjectBehavior/>
        </i:Interaction.Behaviors>
    </Path>
    <Path x:Name="ground" Data="M-44.067795,341.94916 L-42.372677,448.72897 L623.77551,458.89828 C623.77551,458.89828 701.74689,324.99976 559.36407,345.33881 C416.98132,365.67786 515.34595,348.01489 459.40991,344.62506 C403.47385,341.23523 482.81827,225.59961 318.40018,217.125 C153.98207,208.65039 246.22571,330.67603 156.38902,347.62524 C66.552315,364.57446 120.60165,352.87775 76.530815,356.26758 C32.459984,359.65741 -38.731361,341.01331 -38.731361,341.01331 z" Fill="#FFB2520A" Height="243.194" Canvas.Left="-44.568" Stretch="Fill" Stroke="Black" Canvas.Top="216.204" UseLayoutRounding="False" Width="690.101">
        <i:Interaction.Behaviors>
            <pb:PhysicsObjectBehavior IsStatic="True"/>
        </i:Interaction.Behaviors>
    </Path>

  </Canvas>
</UserControl>

 

Thanks ,

Ophir

Coordinator
Apr 24, 2011 at 2:47 AM

The latest release of the Physics Helper uses Farseer 3.x, which behaves much better with Convex polygons (there is a reason for this, the math for collisions with convex polygons is much more simple than concave).

Because of this, there are issues with boundary determination if your polygon is not convex in shape. In the future this might get better with the addition of more boundary detection algorithms.

To check this problem, set DebugMode="true" on the PhysicsControllerBehavior.