이 질문은 많은 질문을받을 수 있으며, 미안하다는 점을 알고 있습니다. 하지만 잠시 동안 내 게임에서 충돌이 생겨서 도움이 필요합니다.XNA 2D Platformer 충돌 및 중력
먼저 게임은 2D 플랫폼입니다. 각 솔리드는 목록에 배치됩니다. 나는 나를 위해 꽤 좋은 작품 충돌 감지에 대한이 코드를 가지고 : 문제는 플레이어가 사각형과 교차하지 않을 경우 I 따라서 그는 계속해서 그와 충돌로 폭포에의 중력을 설정한다는 것입니다 그러나
if (player.rectangle.Intersects(rect))
{
player1Collision = true;
colSolid = solid;
colRectangle = rect;
}
if (player1Collision)
{
Vector2 pos = player.position;
Vector2 pLeft = new Vector2(player.BoundingBox.Left, 0);
Vector2 pRight = new Vector2(player.BoundingBox.Right, 0);
Vector2 pTop = new Vector2(0, player.BoundingBox.Top);
Vector2 pBottom = new Vector2(0, player.BoundingBox.Bottom);
Vector2 sLeft = new Vector2(colSolid.BoundingBox.Left, 0);
Vector2 sRight = new Vector2(colSolid.BoundingBox.Right, 0);
Vector2 sTop = new Vector2(0, colSolid.BoundingBox.Top);
Vector2 sBottom = new Vector2(0, colSolid.BoundingBox.Bottom);
if (player.rectangle.Intersects(colRectangle))
{
if (player.velocity.X > 0 && Vector2.Distance(pRight, sLeft) < player.texture.Width/2)//left
{
player.velocity.X = 0f;
pos.X = colSolid.BoundingBox.Left - player.BoundingBox.Width;
}
else if (player.velocity.X < 0 && Vector2.Distance(pLeft, sRight) < player.texture.Width/2)//right
{
player.velocity.X = 0f;
pos.X = colSolid.BoundingBox.Right;
}
if (player.velocity.Y > 0 && Vector2.Distance(pBottom, sTop) < player.texture.Height/ 2) //top
{
player.velocity.Y = 0f;
player.gravityOn = false;
pos.Y = colSolid.BoundingBox.Top - player.BoundingBox.Height;
}
else if (player.velocity.Y < 0 && Vector2.Distance(pTop, sBottom) < player.texture.Height/2)//bottom
{
player.velocity.Y = 0f;
pos.Y = colSolid.BoundingBox.Bottom;
}
player.position = pos;
}
else
{
player.gravitySpeed = 0.15f;
player.gravityOn = true;
}
}
단단한 다음 그것을 충돌하지 않기 위해 위에 올려 놓는다. 내가 알아야 할 것은 : 어떻게 이것을 피할 수 있습니까? 플레이어를 계속해서 솔리드로 떨어 뜨리지 않고 중력을 계속 설정할 수있는 다른 방법이 있습니까? 단단한 솔기 위로 다시 떨어 뜨리면 다시 떨어질까요?
도움을 주시면 감사하겠습니다.
이 질문은 [gamedev 사이트] (http://gamedev.stackexchange.com)에 더 적합 할 수 있습니다. 내가이 플래그를 마이 그 레이션하기를 원한다면 알려주십시오. –