Advice sought on fastest method for raycasting below objects
Posted: Tue Aug 14, 2012 3:28 am
Hey Norbo, I just wanted to ask your advice on the relative speeds of these two possible methods of getting this job done.
I'm working on a graphically 2D legend of zelda style game, but with jumping and movable objects. Every creature and moving object has a shadow which is cast directly below it onto the ground. These shadows need to know when there is an object below their owner which they should be cast onto, instead of being drawn at ground height. In order to do this my simplest solution was to raycast down from the center of each object every frame, and check for which collision was the highest. However, this method makes use of the Space.Raycast method, the one which returns a whole list of results, which I'm afraid might test against every object in the space. Is this true, or does BEPU's spatial partitioning make this not such a big deal?
The other method (I can think of) would be to use a stripped down version of your character controller's support system, with a bounding box collecting possible supports below the object, and then a raycast being tested against only the support candidates gathered by the bounding box. The only issue here is that the bounding box would have to be quite tall, tall enough that something very high in the air could still detect and cast a shadow onto the ground.
Is the second one clearly better? It's a bit more work, but you must have created the collector box on the character controller for a reason, and if that reason is to eliminate unnecessary raycasts, I should probably steal the idea for something which is going to be done by every moving physics object in my game.
Thanks for reading Norbo,
Alex
I'm working on a graphically 2D legend of zelda style game, but with jumping and movable objects. Every creature and moving object has a shadow which is cast directly below it onto the ground. These shadows need to know when there is an object below their owner which they should be cast onto, instead of being drawn at ground height. In order to do this my simplest solution was to raycast down from the center of each object every frame, and check for which collision was the highest. However, this method makes use of the Space.Raycast method, the one which returns a whole list of results, which I'm afraid might test against every object in the space. Is this true, or does BEPU's spatial partitioning make this not such a big deal?
The other method (I can think of) would be to use a stripped down version of your character controller's support system, with a bounding box collecting possible supports below the object, and then a raycast being tested against only the support candidates gathered by the bounding box. The only issue here is that the bounding box would have to be quite tall, tall enough that something very high in the air could still detect and cast a shadow onto the ground.
Is the second one clearly better? It's a bit more work, but you must have created the collector box on the character controller for a reason, and if that reason is to eliminate unnecessary raycasts, I should probably steal the idea for something which is going to be done by every moving physics object in my game.
Thanks for reading Norbo,
Alex