Problem with On Collision

Sep 1, 2009 at 6:19 PM

Hi, I'm new on Farseer Physics, however I think that is a great tool in the programation of XNA games on 1D,

This is my problem. In my 2D game the character collide with the ground, but I want that he jump. For that  I need to call the method bool OnCollision, that needs two geoms, (surface and character) and a contactList that is my .            I made a contactlist, and I add the two contacts, but, maybe my contacts are wrong or I don't know where is the problem. Because the program shows the error " Object reference not set to an instance of an object"

this is what I do in the LoadContect of my "Game1" class

//lucky= class of my character

//piso=class of my floor

<font size="2">



new Contact(lucky.getPosition(), new Vector2(0,1) , 0f, new ContactId (lucky.getGeom().Id,1, piso.getGeom().Id)));


<font size="2">



new Contact(piso.getPosition(), new Vector2(0, 1), 0f, new ContactId(piso.getGeom().Id, 1, lucky.getGeom().Id)));

and in the update



<font size="2">



this.Content, gameTime,  piso.getGeom(),contactList);

and in lucky Update where I change the state of my character to jump



else if (geometria.OnCollision(geometria, geometria2, contacto) && CurrentKeyboardState.IsKeyDown(Keys.J))




<font size="2">

mCurrentState =




 The error " Object reference not set to an instance of an object" happend in the "else if". However the contact list is not empty, because I add the contacts. If someone can help me I will apreciate it, I have weeks trying to make a simple jump

Sorry, maybe is a noob problem

Thanks a lot


Sep 1, 2009 at 6:41 PM

I just explained how to use the OnCollision delegate in this thread. You don't need the OnCollision delegate to make your player jump. You can use the myPlayerGeom.ApplyImpulse() method to apply an impulse to the geometry. If you player stand on the ground, simply execute this:

MyPlayerGeom.ApplyImpulse(new Vector2(0, 50));

The values depend on your game. Supply it with the values you need.