Jump to content

April 2017 »

23 242526272829

Recent Entries

Recent Entries

- - - - -

Edge Clipping

4: Adsense

Well, that was all a bit hardcore. Decided that the only way I could get edge walking working the way I wanted was to preprocess the edges to turn this:

Attached Image

Into this:

Attached Image

I was going just add the edges manually in the editor, but I thought this would get awkward so wanted to have a way to have it sorted automatically and now we have. Its run in the game as a preprocessing step although I might move it out at some point.

The idea is that each shape maintains a list of edges, with start, end and normal for use in the edge walking system. The preprocess starts by setting the edges around the top of each shape so you get the first image.

The challenge then is to convert these edges so that where two edges are coincident, they get clipped out. My algorithm runs through each edge, uses the physics broadphase to get all the shapes that are potentially colliding then compares each edge on that shape to the current edge. Getting a t >= 0 <= 1 value, it then generates a clip-list for the segment, with each item in the list representing a range of the segment that is coincident with another edge.

Then it is a simple (ha ha ha) process of inverting the range, and generating a new edge list for the sections of the original segment that are not covered by the clip list.

So now, you can walk up to any edges but not walk off them, a la Tomb Raider 1. Phew.

Note: GameDev.net moderates comments.