Raycasting with shapes?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Clavus
Prole
Posts: 28
Joined: Wed Jan 27, 2010 12:45 pm

Raycasting with shapes?

Post 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?
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Raycasting with shapes?

Post 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.
User avatar
Clavus
Prole
Posts: 28
Joined: Wed Jan 27, 2010 12:45 pm

Re: Raycasting with shapes?

Post 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?
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 78 guests