getting conditions to work

Apr 15, 2011 at 12:31 PM

Hi all,

I'm trying to destroy an object from code behind in Silverlight/Farseer physics/Physics Helper 4/C#. (I posted a thread resembling this one in the Farseer forum but realised it was more geared towards PH.)

I wrote this code:
if (sprite1.Name.StartsWith("iObject") && sprite2.Name.StartsWith("eDestroy"))
{
if (Math.Abs(sprite1.BodyObject.AngularVelocity) > 15) //if a "real" hit, regardless of direction [I know this should really be a value derived from LinearVelocity, perhaps the hypothenuse using Pythagoras's theorem?]
{

World.DestroyBody(sprite2); //doesn't work because "FarseerPhysics.Dynamics.World does not contain a definition for DestroyBody."

sprite2.BodyObject.DestroyFixture(sprite2.BodyObject.FixtureList[0]); //another idea that I don't really know what it's doing
}
return;
}

All I'm trying to do is to get the explodebehaviour to fire, so that I get these little particles and the object disappears, but I don't know how to trigger this in code.

An alternative would be to do this in Blend, and just attach the ExplodeBehavior (and DestroyBehavior too?). However, I still want the object to explode only if the velocity of the first object is greater than a specified value. There is a Conditions list in Blend, but I can't find the velocity values, only the values of the object. How would I write this is Blend, if at all possible?

Thanks a lot for any hints,

Pettrer

Apr 19, 2011 at 12:33 AM

I received a reply in the farseer Physcis forum (use World.RemoveBody). However, I don't think I'll get the nice explode effect by doing that.

/Pettrer

Coordinator
Apr 19, 2011 at 1:14 AM

The explode effect is really just a simple Storyboard animation. You could look at the user control, ucExplode, to get an idea of the animation. You could even use ucExplode as the effect programmatically - just set the Left, Top position of the control and start the animation.

Apr 20, 2011 at 6:16 AM
AndyBeaulieu wrote:

The explode effect is really just a simple Storyboard animation. You could look at the user control, ucExplode, to get an idea of the animation. You could even use ucExplode as the effect programmatically - just set the Left, Top position of the control and start the animation.


Got it. Thanks!

/Pettrer