tinycavestory
tinycavestory copied to clipboard
Character walks into walls
fix:
// quote's physics integration
quote_vel_y += dt * -250.0f;
quote_x += dt * quote_vel_x;
quote_y += dt * quote_vel_y;
// quote's collision detection and collision resolution
for (int i = 0; i < tile_count; ++i)
{
tile_t tile = tiles[i];
if (tile.shape_id == -1) continue;
shape_t shape = shapes[tile.shape_id];
shape = get_transformed_tile_shape(tile, shape);
c2Manifold m;
quote_circle.p = c2V(quote_x, quote_y); // update for every check
c2Collide("e_circle, 0, C2_CIRCLE, &shape.u, 0, shape.type, &m);
if (m.count)
{
// move quote out of colliding configuration
float depth = -m.depths[0];
c2v n = m.n;
quote_x += n.x * depth;
quote_y += n.y * depth;
// "slide along wall"
// remove all velocity in the direction of the wall's normal
// v -= n * dot(v, n)
c2v v = c2V(quote_vel_x, quote_vel_y);
v = c2Sub(v, c2Mulvs(n, c2Dot(v, n)));
quote_vel_x = v.x;
quote_vel_y = v.y;
}
}
quote_circle.p = c2V(quote_x, quote_y); // update for rendering
quote_sprite.x = quote_x;
quote_sprite.y = quote_y;
I didn't see this! If you post a pull request I'd happily merge it :)