Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

879490 Posts in 32984 Topics- by 24367 Members - Latest Member: bastion_music

May 24, 2013, 07:29:12 AM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Circle vs Axis-Aligned-Rectangle/Circle collision and resolution
Pages: 1 [2]
Print
Author Topic: Circle vs Axis-Aligned-Rectangle/Circle collision and resolution  (Read 1236 times)
Glaiel-Gamer
Moderator
Level 10
******


Stoleurface!


View Profile WWW Email
« Reply #15 on: May 18, 2012, 11:39:44 AM »

You can do linesegment-v-rectangle by testing the segment along both diagonals of the rectangle, and testing if the endpoints of the segment are inside the rectangle. You won't need this for a swept collision since we'll replace the endpoints with a circle

we'll also assume that the ground is static



c2 is the old circle position, c1 is the new circle position

we don't need to test c2, because it wasn't colliding on the previous frame

we just need to test C1 with R (algorithm i posted above), L1 with L3&l4, L2 with L3&L4

since L1 and l2 are parallel you only need to test the one closest to the rectangle's center




ISSUES:
if the circle is very large compared to the rectangle it can skip over it (L1 above the rectangle L2 below it), can solve by adding an L3through the circle's center, or more if necessary


other notes: writing down the math for testing L1 with the rectangle diagonals, I believe there is a way to test both diagonals with a single equation assuming the rectangle is axis aligned, but I don't remember how right now
Logged

Glaiel-Gamer
Moderator
Level 10
******


Stoleurface!


View Profile WWW Email
« Reply #16 on: May 18, 2012, 11:41:47 AM »

also if you do one line (just through the circle's centers), and extrude the diagonals of the rectangle out by the circle's radius, that might work too and would solve the contingency where the circle is huge
Logged

raigan
Level 4
****


View Profile
« Reply #17 on: May 18, 2012, 04:06:51 PM »

Yeah.. uh, I think multi-sampled signed-distance queries is probably the easiest thing to do. Sorry for over-complexifying the issue!
Logged
st33d
Guest
« Reply #18 on: May 19, 2012, 02:18:20 AM »

The reason I didn't want to multi-sample is because the character is very small. It may result in a shit-load of samples, giving me some really bizarre chugging in situations where you want the game to run smooth because you're doing something fast and fancy.

The trouble with raycasting is that there are edge cases it doesn't solve.

-

It looks like I won't be using this collision in the game anyhow. The management want it to be about hanging on to cogs that spin round and fling you off. They're very much against any grappling gameplay, so putting in any walls at all will just end up with grappling gameplay. (What's wrong with grappling gameplay you say? That's what I thought, but they've started going on about, "what was in my head", so it's not going to be an exploratory design.)

I'll leave this topic open anyway because I'm pretty sure I'm going to have to come back to this problem.
Logged
raigan
Level 4
****


View Profile
« Reply #19 on: May 19, 2012, 05:14:47 AM »

The trouble with raycasting is that there are edge cases it doesn't solve.

Could you describe/explain those at all? I'd be quite interested to know what problems you ran into, because prior to using a slightly-shrunken raycasting shape, every time I've tried raycast-based collision detection (rather than penetration-/distance-based) there have been some glitches... however so far the "raycast a shrunken core" method has been working for us.

(AFAIK the "shrunken core" idea is how e.g Box2d/Bullet approach continuous collision -- they use conservative advancement rather than raycasts, but the idea is the same)


It looks like I won't be using this collision in the game anyhow. The management want it to be about hanging on to cogs that spin round and fling you off. They're very much against any grappling gameplay, so putting in any walls at all will just end up with grappling gameplay. (What's wrong with grappling gameplay you say? That's what I thought, but they've started going on about, "what was in my head", so it's not going to be an exploratory design.)

Too bad -- there are never enough grappling-based games in the world! Sad
Logged
Pages: 1 [2]
Print
Jump to:  

Theme orange-lt created by panic