RE: [Algorithms] 2D Platform game problem:implementing cloud platforms
Brought to you by:
vexxed72
From: <bu...@ms...> - 2004-11-22 14:56:18
|
Hi, > You might be wondering then how to deal with intersections between the top > of your character (his "head") and the environment (and indeed, the sides > of the character...you don't want him dropping through platforms until > he's reached the very edge of them). To solve this, just expand the line > segments defined by your platforms outward based on their surface normal. > So, downward facing normals would be expanded downard by the height of > your character. This will give you the effect of your character having a > volume in your world, instead of being treated as a single point. This approach to giving sprites volume works fine as long as all sprites are the same size. However it is likely that your game will feature sprites of varying sizes. In this case it rapidly becomes very unwieldy to try to expand collision geometry dynamically. Another solution is to use a bounding box for the sprites for collision. This now involves sweeping a box along the path of the sprite instead of just a point. This makes for more complex collision testing than the previous simple ray test. However we can reduce the problem back to a number of ray tests quite simply. First we must realise that any possible collision between two edges must involve a collision between a vertex and an edge (this is true even in the degenerate line v line case). Therefore to check for collision we can first perform a ray test from the four vertices of the sprite's bounding box along the velocity of the sprite. This will catch half the possible cases - the other half can be caught by performing a ray test from the vertices of the world along the *negative* velocity of the sprite. This will of course give collisions at the wrong point in world space - however we can then use the collision time to calculate the correct collision point in world space. Perhaps a few diagrams will clarify: Case 1: ------- | | | | / | | / | | / -------/ / / / In this case the collision is between a vertex of the sprite and an edge of the world. This collision will be detected by a ray test from the vertex along the velocity of the sprite. Case 2: ------- | | | | | | | | ------- / / / In this case the collision is between an edge of the sprite and a vertex of the world. This collision will be detected by a ray test from the vertex of the world along the *negative* velocity of the sprite. Michael Smith Disembodied Spirit of Sir Robert Menzies --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.794 / Virus Database: 538 - Release Date: 10/11/2004 |