Friday, December 1, 2017

xna - Detect Open Space in Farseer






Possible Duplicate:
How do I detect ledges?



I'm working on a 2D platformer using XNA and Farseer. I would like the player's character to be able to grab and climb up ledges. Detecting a collision between the player and the side of a wall is simple enough with the OnCollision delegate, but I have to admit I'm a bit stumped on how to detect that there's enough clearance for the PC to mount the ledge.


Essentially, I want to ensure there's an appropriately sized rectangle above and to the left or right of the PC (depending on their direction) and I'm not sure how I would check for such a space.


Any suggestions on how to determine there is nothing in the simulated world within some bounding rectangle?



Answer



The video for Overgrowth Alpha 132 shows how they implemented ledge climbing: http://www.youtube.com/watch?v=GFu44oeLYPI


Their method should work in any engine, even 2D engines where you'd use a rectangle and circle instead of a cylinder and sphere.




Their ledge detection involves two parts:


Wall detection (using the sphere)


The game checks if the player's currently colliding with a wall. If there's a wall, there might be ledges the player can grab onto. The second part takes over to analyse the ledges.


Ledge detection (using the cylinder)


If the player's contacting a wall, a cylinder is swept downwards from a certain distance above the player's position until it touches a ledge. This can determine three things:



  • Whether a ledge exists above the player

  • The ledge's height

  • Whether there is room for the player to climb up onto the ledge, considering the cylinder occupies the same horizontal space as the player.



No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...