Page 1 of 1

Raycasting with shapes?

Posted: Mon Apr 29, 2013 11:41 am
by Clavus
To give some context for this problem: I have a top-down game where the player slashes with his sword in a quarter-ish circle arc. I use the physics system to detect what bodies it hit. Right now, the only way I can think of doing this is is by casting multiple rays distributed over the triangle area I want to check using World:rayCast, storing the results (per callback) in a list, removing duplicates from the list once all the collision events are done, then process the 'hit-by-sword' event for every one of those. It strikes me as overly complicated though.

I'm wondering if there isn't a simpler way to do this. Is it possible to do a sort-of-raycast with a shape or set of shapes?

Re: Raycasting with shapes?

Posted: Mon Apr 29, 2013 2:19 pm
by Plu
Maybe create a cone shape, put it on sensor mode, and then just activate it for a few frames when the sword is swinging?

You should get all the collisions it's making then.

Re: Raycasting with shapes?

Posted: Mon Apr 29, 2013 2:23 pm
by Clavus
That solution jumped to mind before. Requires some additional coding to put into a single function call but I guess it's do-able. That would be the easiest / robust solution then?