# (C#)Help with PhysX.Net code.

This topic is 3087 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm using the PhysX.Net Wrapper to use the PhysX SDK with C#. I have put together a bit of code which is supposed to apply some force to a box, making it move down the screen. However, the box just stays in the same place (0,0) and doesn't move at all. I have looked through the code and I can't see anything wrong. Here are snippets of the code which deals with physics: Initiallization:
public TestForm( )
{
SlimDX.Configuration.ThrowOnError = false;

Application.Idle += new EventHandler( OnIdle );
this.Size = new Size( 800, 600 );
this.Visible = true;

init3D();
createPhysics();
updateTime(); // initial time update
updatePhysics(); // update the physics for the first time
}


Physics update functions:
private void update( )
{
scene.FetchResults( SimulationStatus.RigidBodyFinished, false );

updatePhysics();
}

private void updatePhysics( )
{
updateTime();

scene.Simulate( (float)elapsedTime.TotalSeconds );
scene.FlushStream();
}

private void updateTime( )
{
TimeSpan currTime = TimeSpan.FromTicks( Stopwatch.GetTimestamp() );
elapsedTime = currTime - lastFrameTime;

lastFrameTime = currTime;
}


Actor Creation Function:
bool createSquare( )
{
ActorDescription actorDesc = new ActorDescription();

BoxShapeDescription boxDesc = new BoxShapeDescription( 300, 300, 1 );
if (!boxDesc.IsValid())
{
return false;
}
BodyDescription bodyDesc = new BodyDescription( 10.0f );

if (!bodyDesc.IsValid())
{
return false;
}

actorDesc.BodyDescription = null;//bodyDesc;//bodyDesc;
actorDesc.Density = 10.0f;

if (!actorDesc.IsValid())
{
return false;
}

squareActor = scene.CreateActor( actorDesc );

return true;
}


A little rendering snippet:
device.Clear ( ClearFlags.ZBuffer | ClearFlags.Target, Color.DarkViolet.ToArgb (), 1.0f, 0 );
device.BeginScene ();

sprite.Transform = squareActor.GlobalOrientation;
sprite.Begin(SpriteFlags.AlphaBlend);
sprite.Draw( texture, new Color4( Color.White ) );

sprite.End();

device.EndScene();

device.Present();


And of course, where I actually apply force:
protected override void OnKeyDown( KeyEventArgs e )
{
if (e.KeyCode == Keys.A)
{
squareActor.AddForce( new Vector3( 100, 100, 0 ), ForceMode.SmoothImpulse );
}
}


I have been grinding my teeth over this for hours. Help would be greatly appreciated.

##### Share on other sites
Anyone?
This is my first time using physics and I have no clue what's wrong..

##### Share on other sites
Try setting a breakpoint to where you add the force and see if the appropriate values change, then see if it is being rendered. It may be the fact that your box is being moved, but it's not being rendered again.