나는 게임에서 벽에 충돌하고 있으며 현재 내가 벽에 걸린 채 붙어 있습니다. 나는 벽에 내 캐릭터 슬라이드를 만들려고하지만 여전히 충돌합니다.3D 벽 슬라이딩 충돌
내 캐릭터가 자신이 직면 한 각도로 작성한 벡터에서 벗어납니다. 이것은 내 업데이트입니다
private static bool CheckForCollisions(ref Crate c1, ref Player c2,bool direction)
{
for (int i = 0; i < c1.model.Meshes.Count; i++)
{
// Check whether the bounding boxes of the two cubes intersect.
BoundingSphere c1BoundingSphere = c1.model.Meshes[i].BoundingSphere;
c1BoundingSphere.Center += c1.position + new Vector3(2, 0, 2);
c1BoundingSphere.Radius = c1BoundingSphere.Radius/1.5f;
for (int j = 0; j < c2.model.Meshes.Count; j++)
{
BoundingSphere c2BoundingSphere = c2.model.Meshes[j].BoundingSphere;
if (direction)
c2BoundingSphere.Center += c2.position + new Vector3(c2.getPlannedDirection().X, 0, 0);
else if (!direction)
c2BoundingSphere.Center += c2.position + new Vector3(0, 0, c2.getPlannedDirection().Y);
//c2BoundingSphere.Center += c2.position;
if (c1BoundingSphere.Intersects(c2BoundingSphere))
{
return true;
}
}
}
return false;
}
:
이
내 충돌 기능입니다for (int x = 0; x <= 29; x++)
{
for (int y = 0; y <= 29; y++)
{
if (crate[x, y].getType() == 11 && collisionEnabled)
{
if (CheckForCollisions(ref crate[x, y], ref player,true))
{
player.clearPlannedDirectionX();
//Console.Write(player.getPosition().X + "," + player.getPosition().Y + "," + player.getPosition().Z);
//movePlayer = false;
}
if (CheckForCollisions(ref crate[x, y], ref player,false))
{
player.clearPlannedDirectionZ();
//Console.Write(player.getPosition().X + "," + player.getPosition().Y + "," + player.getPosition().Z);
//movePlayer = false;
}
}
}
}
getPlannedDirection()을 사용하고있다. .X 및 getPlannedDirection(). 첫 번째에서 Y 코드를 사용하고 있지만 clearPlannedDirectionX() 및 clearPlannedDirectionZ()를 두 번째로 사용하고 있습니다. –
예, z 축에 충돌이 발생하면 멈추게됩니다. x 축과 동일합니다. 이것은 플레이어가 위치를 업데이트하기 전에 모두 실행됩니다. 그것이 "PlannedDirection"이라고 불리는 이유입니다. 미안하지만 내 질문에 그 점을 명확히해야했습니다. – bbdude95