- Collsion Resolution / Physics - The way you resolve collisions is very game dependant. Every game I've worked on had a different way resolving collisions - One Extreme -- Mathmatically Correct Physics - Simulate based on applying forces - F = ma, so you end up setting acceleration - From acceleration, you can calculate velocity, position - v' = v + a dt, p' = p + v dt - Common forces: Friction, Gravity - Enforce Conservation of (linear + angular) momentum - Other Extreme -- "Game" physics - Simulate by setting velocities - No conservation of momentum - Can be thought of as modelling Mathematically correct physics with a super huge friction that would always stop you instantly. - The usual solution is somewhere in the middle. Where depends on the type of game. - Examples that would be relevant to your projects: - Adventure game physics (for Blind Samurai, Excitement Challenge) - Commonly used in top-down adventure games, like Legend of Zelda or God of War. - Usually velocity based - Sometimes the velocity is smoothed, so that you do not stop instantly - No state machine needed; you are always on the ground - How does it handle Collision Resolution w/ Background? - Just disallow player from entering cell. Algorithm is: - Look at direction of movement and figure out where you would be at the time of collision, see what edges are touching - If you cap velocity low enough, you could also just look at where your AABB/Capsule/Circle is in the tile. - Velocity usually has a very low max, so the previous simplification is quite doable. :) - Often you will want to add a "buffer zone" to the corners of the tiles where the player will be snapped around the tile (perpendicular to velocity) so the player can get around tiles. - How does it handle Collision Resolution w/ Objects? - Usually by cheating - if you would collide, take damage and get pushed back - The push back prevents the player from colliding next frame - Often the player becomes invincible so that you don't collide again. - Also helps avoid colliding next frame - If you collide with an item, pick it up and remove it from the physics - Platformer physics (MOD Shell) - Mario, Sonic, even modern games like Batman: Arkham Asylum - Simulation is Psuedo-acceleration based - Physics tends to stateful -- Common states are "On_Platform", "In_Freefall", and "Jumping_Freefall" - Each state has different behavior for physics. - How does "On_Platform" work? - Player is glued to ground. He will follow the path of the ground, even if it has inclines. - Conservation of momentum is commonly simulated in different ways - Keep constant magnitude (walking up a hill slows you down based on the steepness) -- Sonic style - Keep axial component (walking up a hill does not slow you down much, if at all) -- Mario style - Gravity / Friction - Gravity is *not* simulated - Friction is simulated by a drag velocity that slows you down if you are not pressing a direction. - How does "In_Freefall" work? - Acceleration based physics with a gravity accel added each frame. - Some terminal velocity; clamp the player's fall speed to never be more than this. - How does "Jumping_Freefall" work? - Set upward velocity until button is released or time runs out - "Up" could be normal to the plane of ground where jumping -- Sonic style - "Up" is always straight up -- Mario style - How do all the prior states support collision resolution w/ background? - Just like Adventure Game Physics - Also, you may want to think about being nice and letting the player land on the platform as often as possible - How do all the prior states support collision resolution w/ objects? - Often cheated -- if you would collide, just don't move in X/Y and adjust your velocity to "bounce" - Ensures you are not colliding next frame! - Mario would put you back in the "jumpping" state, with a longer timer, so you can keep jumping over and over again.