tinycavestory icon indicating copy to clipboard operation
tinycavestory copied to clipboard

Character walks into walls

Open 1vanK opened this issue 7 years ago • 1 comments

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(&quote_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;

1vanK avatar Sep 29 '18 22:09 1vanK

I didn't see this! If you post a pull request I'd happily merge it :)

RandyGaul avatar Feb 06 '19 06:02 RandyGaul