Help with raycast

Topics: Developer Forum
Apr 9, 2013 at 3:47 PM
Hi, I'm currently trying to create a side scrolling game but are having some difficulties when jumping. What I want is a convenient way to check if the player is in midair. I have tried to use raycast to check the distance to the ground but I can't get it to work properly.
So does anyone know a good tutorial on raycasting or another way to check if the player is jumping?
Apr 9, 2013 at 8:24 PM
Hi Athyl,

I think I can help you. Farseer is based on Box2D so when I had this same problem I did some searching on Box2D and found this helpful article.

I basically used the technique described there to implement the "am I in the air?" functionality in my game. Once you've added the "ground sensor" (as described in the article) you can use code I shared in this thread to test if your sensor is in contact with the ground. The article suggests using a contact counter to keep track of whether you're in the air or not, but I didn't have much luck when I tried that. Instead I just loop through the contact list on my sensor each Update and see if my sensor is in contact with the ground.

Hope that helps.

Good luck!
Mike.