This project has moved and is read-only. For the latest updates, please go here.

Determine top Y coordinate for body with multiple fixtures

Jan 11, 2013 at 1:30 AM

I built a side scroller using one body as the ground.  I have a camera that follows a sprite.  what I want to do is when the sprite jump have the camera zoom out far enough where the ground is still in view.  My thought was to compare the X value of the sprite and try to determine the highest Y of the ground then have the camera zoom out until they are both there.

Is there a good way to determine the Y value for the ground?  Is there a better way to approach this thing?

Jan 12, 2013 at 1:06 PM

One way is to shoot a ray (World.Raycast()) from your player position downwards to find out the highest ground below the player.

Jan 14, 2013 at 7:05 PM

I ended up finding an easier way to do it. I basically recorded the sprites Y on collision with the ground.  Then on update I calculated the difference between current Y and the Y of the last collision. Then based on the difference I calculated the zoom level.