Commit e901a5c2 authored by 18신대성's avatar 18신대성

거울 알고리즘 수정 및 마네킹 트리거 위치조정

parent 1be4a515
...@@ -11,7 +11,6 @@ GameObject: ...@@ -11,7 +11,6 @@ GameObject:
- component: {fileID: 7532712444690926276} - component: {fileID: 7532712444690926276}
- component: {fileID: 2757119551192804292} - component: {fileID: 2757119551192804292}
- component: {fileID: 1737342363823857601} - component: {fileID: 1737342363823857601}
- component: {fileID: 7820135686568696358}
m_Layer: 0 m_Layer: 0
m_Name: Cylinder (1) m_Name: Cylinder (1)
m_TagString: Untagged m_TagString: Untagged
...@@ -79,20 +78,6 @@ MeshRenderer: ...@@ -79,20 +78,6 @@ MeshRenderer:
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 0 m_SortingOrder: 0
--- !u!136 &7820135686568696358
CapsuleCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4214528635841560197}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
m_Radius: 0.5000001
m_Height: 1.9999998
m_Direction: 1
m_Center: {x: 0.000000059604634, y: 0, z: -0.00000008940695}
--- !u!1 &6169104080419908224 --- !u!1 &6169104080419908224
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
...@@ -1091,7 +1076,7 @@ CapsuleCollider: ...@@ -1091,7 +1076,7 @@ CapsuleCollider:
m_Radius: 0.14 m_Radius: 0.14
m_Height: 0.67 m_Height: 0.67
m_Direction: 1 m_Direction: 1
m_Center: {x: -0.03, y: 1.07, z: 0.06} m_Center: {x: 0.06, y: 1.28, z: 0.02}
--- !u!136 &7520578024426790809 --- !u!136 &7520578024426790809
CapsuleCollider: CapsuleCollider:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
...@@ -1105,7 +1090,7 @@ CapsuleCollider: ...@@ -1105,7 +1090,7 @@ CapsuleCollider:
m_Radius: 0.06 m_Radius: 0.06
m_Height: 0.82 m_Height: 0.82
m_Direction: 1 m_Direction: 1
m_Center: {x: -0.12, y: 0.34, z: 0.06} m_Center: {x: -0.02, y: 0.64, z: 0.09}
--- !u!135 &8665308411572536972 --- !u!135 &8665308411572536972
SphereCollider: SphereCollider:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
...@@ -1118,7 +1103,7 @@ SphereCollider: ...@@ -1118,7 +1103,7 @@ SphereCollider:
m_Enabled: 1 m_Enabled: 1
serializedVersion: 2 serializedVersion: 2
m_Radius: 0.09 m_Radius: 0.09
m_Center: {x: 0.27, y: 0.59, z: 0.11} m_Center: {x: 0.16, y: 1.68, z: 0.03}
--- !u!135 &3177627456582659259 --- !u!135 &3177627456582659259
SphereCollider: SphereCollider:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
...@@ -1131,7 +1116,7 @@ SphereCollider: ...@@ -1131,7 +1116,7 @@ SphereCollider:
m_Enabled: 1 m_Enabled: 1
serializedVersion: 2 serializedVersion: 2
m_Radius: 0.09 m_Radius: 0.09
m_Center: {x: 0.24, y: 0.23, z: 0.07} m_Center: {x: 0.2, y: 0.36, z: -0.13}
--- !u!135 &6611904422136213405 --- !u!135 &6611904422136213405
SphereCollider: SphereCollider:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
...@@ -1144,7 +1129,7 @@ SphereCollider: ...@@ -1144,7 +1129,7 @@ SphereCollider:
m_Enabled: 1 m_Enabled: 1
serializedVersion: 2 serializedVersion: 2
m_Radius: 0.09 m_Radius: 0.09
m_Center: {x: 0.32, y: 0.45, z: 0.13} m_Center: {x: 0.27, y: 0.53, z: -0.11}
--- !u!136 &547261276454492544 --- !u!136 &547261276454492544
CapsuleCollider: CapsuleCollider:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
...@@ -1156,9 +1141,9 @@ CapsuleCollider: ...@@ -1156,9 +1141,9 @@ CapsuleCollider:
m_IsTrigger: 1 m_IsTrigger: 1
m_Enabled: 1 m_Enabled: 1
m_Radius: 0.08 m_Radius: 0.08
m_Height: 0.4 m_Height: 0.27
m_Direction: 1 m_Direction: 1
m_Center: {x: 0.24, y: 1.32, z: 0.11} m_Center: {x: -0.1, y: 1.31, z: 0.12}
--- !u!135 &1057832123483110392 --- !u!135 &1057832123483110392
SphereCollider: SphereCollider:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
...@@ -1171,7 +1156,7 @@ SphereCollider: ...@@ -1171,7 +1156,7 @@ SphereCollider:
m_Enabled: 1 m_Enabled: 1
serializedVersion: 2 serializedVersion: 2
m_Radius: 0.11 m_Radius: 0.11
m_Center: {x: 0.13, y: 1.29, z: 0.06} m_Center: {x: 0.19, y: 0.89, z: -0.09}
--- !u!135 &2060313653279296710 --- !u!135 &2060313653279296710
SphereCollider: SphereCollider:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
...@@ -1183,8 +1168,8 @@ SphereCollider: ...@@ -1183,8 +1168,8 @@ SphereCollider:
m_IsTrigger: 1 m_IsTrigger: 1
m_Enabled: 1 m_Enabled: 1
serializedVersion: 2 serializedVersion: 2
m_Radius: 0.06 m_Radius: 0.08
m_Center: {x: 0.1, y: 1.47, z: 0.15} m_Center: {x: 0.26, y: 1.47, z: -0.1}
--- !u!135 &5008880329460952899 --- !u!135 &5008880329460952899
SphereCollider: SphereCollider:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
...@@ -1197,7 +1182,7 @@ SphereCollider: ...@@ -1197,7 +1182,7 @@ SphereCollider:
m_Enabled: 1 m_Enabled: 1
serializedVersion: 2 serializedVersion: 2
m_Radius: 0.09 m_Radius: 0.09
m_Center: {x: 0.15, y: 0.74, z: 0.07} m_Center: {x: 0.27, y: 0.69, z: -0.11}
--- !u!1 &6169104080419908268 --- !u!1 &6169104080419908268
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
...@@ -2677,7 +2662,7 @@ GameObject: ...@@ -2677,7 +2662,7 @@ GameObject:
- component: {fileID: 5778541329035756108} - component: {fileID: 5778541329035756108}
m_Layer: 0 m_Layer: 0
m_Name: Cube m_Name: Cube
m_TagString: Untagged m_TagString: Mannequin
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
...@@ -2750,10 +2735,10 @@ BoxCollider: ...@@ -2750,10 +2735,10 @@ BoxCollider:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7055982119285520526} m_GameObject: {fileID: 7055982119285520526}
m_Material: {fileID: 0} m_Material: {fileID: 0}
m_IsTrigger: 0 m_IsTrigger: 1
m_Enabled: 1 m_Enabled: 1
serializedVersion: 2 serializedVersion: 2
m_Size: {x: 0.99999994, y: 0.9999999, z: 0.99999994} m_Size: {x: 2.02, y: 0.9999999, z: 0.99999994}
m_Center: {x: 0, y: 0, z: 0} m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &9160474912727509970 --- !u!1 &9160474912727509970
GameObject: GameObject:
...@@ -2766,7 +2751,6 @@ GameObject: ...@@ -2766,7 +2751,6 @@ GameObject:
- component: {fileID: 2174992776252301311} - component: {fileID: 2174992776252301311}
- component: {fileID: 8219032022057428283} - component: {fileID: 8219032022057428283}
- component: {fileID: 1080991707287384770} - component: {fileID: 1080991707287384770}
- component: {fileID: 8246746603589846495}
m_Layer: 0 m_Layer: 0
m_Name: Cylinder (2) m_Name: Cylinder (2)
m_TagString: Untagged m_TagString: Untagged
...@@ -2834,17 +2818,3 @@ MeshRenderer: ...@@ -2834,17 +2818,3 @@ MeshRenderer:
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 0 m_SortingOrder: 0
--- !u!136 &8246746603589846495
CapsuleCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9160474912727509970}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
m_Radius: 0.5000001
m_Height: 1.9999998
m_Direction: 1
m_Center: {x: 0.000000059604634, y: 0, z: -0.00000008940695}
...@@ -37,21 +37,27 @@ public class Mirror : Wall, IBulletInteractor, IBreakable ...@@ -37,21 +37,27 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
new Pair(0, 1) new Pair(0, 1)
}; };
int side, i, iBack, stCheck; int side, i, reflectSide, mapRange;
bool isSameRSide;
if (dir) // horizontal, parallel with x if (dir) // horizontal, parallel with x
{ {
side = (mapPos.y - stPos.y > 0) ? -1 : 1; side = (mapPos.y - stPos.y > 0) ? -1 : 1;
reflectSide = (mapPos.x - stPos.x > 0) ? 1 : -1;
if (isSameRSide = mapPos.x == stPos.x) mapRange = Mathf.RoundToInt(mapPos.x);
else mapRange = -reflectSide * (MapManager.inst.currentMap.maxMapSize + 1);
i = side > 0 ? Mathf.CeilToInt(mapPos.y) : Mathf.FloorToInt(mapPos.y); i = side > 0 ? Mathf.CeilToInt(mapPos.y) : Mathf.FloorToInt(mapPos.y);
iBack = side < 0 ? Mathf.CeilToInt(mapPos.y) : Mathf.FloorToInt(mapPos.y);
stCheck = (int)stPos.y;
} }
else // vertical, parallel with y else // vertical, parallel with y
{ {
side = (mapPos.x - stPos.x > 0) ? -1 : 1; side = (mapPos.x - stPos.x > 0) ? -1 : 1;
reflectSide = (mapPos.y - stPos.y > 0) ? 1 : -1;
if (isSameRSide = mapPos.y == stPos.y) mapRange = Mathf.RoundToInt(mapPos.y);
else mapRange = -reflectSide * (MapManager.inst.currentMap.maxMapSize + 1);
i = side > 0 ? Mathf.CeilToInt(mapPos.x) : Mathf.FloorToInt(mapPos.x); i = side > 0 ? Mathf.CeilToInt(mapPos.x) : Mathf.FloorToInt(mapPos.x);
iBack = side < 0 ? Mathf.CeilToInt(mapPos.x) : Mathf.FloorToInt(mapPos.x);
stCheck = (int)stPos.x;
} }
//Debug.Log("side: " + side + ", reflectSide: " + reflectSide + ", i: " + i + ", isSameRSide: " + isSameRSide);
//Debug.Log("minRange: " + mapRange);
yield return null; yield return null;
// check before reflect (check walls and mirrors) // check before reflect (check walls and mirrors)
...@@ -76,15 +82,11 @@ public class Mirror : Wall, IBulletInteractor, IBreakable ...@@ -76,15 +82,11 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
floorCountGrid.Add(floor.Key, 0); floorCountGrid.Add(floor.Key, 0);
} }
int minMapRange = -1 * MapManager.inst.currentMap.maxMapSize - 1;
int maxMapRange = MapManager.inst.currentMap.maxMapSize + 1;
// start reflection // start reflection
Vector2Int frontFloorPos = dir ? Vector2Int frontFloorPos = dir ?
new Vector2Int(Mathf.RoundToInt(mapPos.x), Mathf.RoundToInt(mapPos.y + 0.5f * side)) new Vector2Int(Mathf.RoundToInt(mapPos.x), Mathf.RoundToInt(mapPos.y + 0.5f * side))
: new Vector2Int(Mathf.RoundToInt(mapPos.x + 0.5f * side), Mathf.RoundToInt(mapPos.y)); : new Vector2Int(Mathf.RoundToInt(mapPos.x + 0.5f * side), Mathf.RoundToInt(mapPos.y));
int frontFloorCount = 0; if (floorCountGrid.TryGetValue(frontFloorPos, out int frontFloorCount))
if (floorCountGrid.TryGetValue(frontFloorPos, out frontFloorCount))
{ {
if (frontFloorCount == 0) floorCountGrid[frontFloorPos]++; // have floor if (frontFloorCount == 0) floorCountGrid[frontFloorPos]++; // have floor
} }
...@@ -92,12 +94,32 @@ public class Mirror : Wall, IBulletInteractor, IBreakable ...@@ -92,12 +94,32 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
{ {
floorCountGrid.Add(frontFloorPos, -1); floorCountGrid.Add(frontFloorPos, -1);
} }
for (; Mathf.Abs(i) < maxMapRange; i += side) for (; Mathf.Abs(i) < (MapManager.inst.currentMap.maxMapSize + 1); i += side)
{ {
// check walls and copy bool anotherSide = false;
for (float j = minMapRange + 0.5f; j < maxMapRange + 0.5f; j++) for (int j = mapRange; Mathf.Abs(j) <= (MapManager.inst.currentMap.maxMapSize + 1); j += reflectSide)
{ {
Vector2 wallPos = dir ? new Vector2(j, i) : new Vector2(i, j); // check floors
Vector2Int floorPos = dir ? new Vector2Int(j, i) : new Vector2Int(i, j);
Pair floorPair = new Pair(
PointToParRay(stPos, floorPos + 0.5f * (dir ? new Vector2(reflectSide, -side) : new Vector2(-side, reflectSide)), true),
PointToParRay(stPos, floorPos + 0.5f * (dir ? new Vector2(-reflectSide, side) : new Vector2(side, -reflectSide)), true));
if (IsInRay(parRay, floorPair))
{
int floorCount;
if (floorCountGrid.TryGetValue(floorPos, out floorCount))
{
if (floorCount == 0) floorCountGrid[floorPos]++; // have floor
}
else // no floor on there
{
floorCountGrid.Add(floorPos, -1);
}
}
// check walls and copy
Vector2 wallPos = dir ? new Vector2(j + 0.5f * reflectSide, i) : new Vector2(i, j + 0.5f * reflectSide);
//Debug.Log(wallPos);
Vector2 oppoPos = GetOpposite(wallPos); Vector2 oppoPos = GetOpposite(wallPos);
Pair wallPair = dir ? Pair wallPair = dir ?
(new Pair(PointToParRay(stPos, wallPos + new Vector2(0, -0.5f), true), PointToParRay(stPos, wallPos + new Vector2(0, 0.5f), true))) : (new Pair(PointToParRay(stPos, wallPos + new Vector2(0, -0.5f), true), PointToParRay(stPos, wallPos + new Vector2(0, 0.5f), true))) :
...@@ -115,29 +137,29 @@ public class Mirror : Wall, IBulletInteractor, IBreakable ...@@ -115,29 +137,29 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
if (copyWallGrid.ContainsKey(oppoPos)) MapManager.inst.currentMap.RemoveWall(oppoPos); if (copyWallGrid.ContainsKey(oppoPos)) MapManager.inst.currentMap.RemoveWall(oppoPos);
} }
} }
}
for (int j = minMapRange + 1; j < maxMapRange; j++) if (isSameRSide && Mathf.Abs(j) == (MapManager.inst.currentMap.maxMapSize + 1))
{
// check floors
Vector2Int floorPos = dir ? new Vector2Int(j, i) : new Vector2Int(i, j);
if (IsInRay(parRay, PointToParRay(stPos, floorPos, true)))
{ {
int floorCount; if (anotherSide)
if (floorCountGrid.TryGetValue(floorPos, out floorCount))
{ {
if (floorCount == 0) floorCountGrid[floorPos]++; // have floor reflectSide *= -1;
anotherSide = false;
break;
} }
else // no floor on there else
{ {
floorCountGrid.Add(floorPos, -1); anotherSide = true;
reflectSide *= -1;
j = mapRange - reflectSide;
} }
} }
} }
float iMid = i + 0.5f * side; float iMid = i + 0.5f * side;
// check walls and copy // check walls and copy
for (int j = minMapRange; j < maxMapRange; j++) for (int j = mapRange; Mathf.Abs(j) <= (MapManager.inst.currentMap.maxMapSize + 1); j += reflectSide)
{ {
Vector2 wallPos = dir ? new Vector2(j, iMid) : new Vector2(iMid, j); Vector2 wallPos = dir ? new Vector2(j, iMid) : new Vector2(iMid, j);
//Debug.Log(wallPos);
Vector2 oppoPos = GetOpposite(wallPos); Vector2 oppoPos = GetOpposite(wallPos);
Pair wallPair = !dir ? Pair wallPair = !dir ?
(new Pair(PointToParRay(stPos, wallPos + new Vector2(0, -0.5f), true), PointToParRay(stPos, wallPos + new Vector2(0, 0.5f), true))) : (new Pair(PointToParRay(stPos, wallPos + new Vector2(0, -0.5f), true), PointToParRay(stPos, wallPos + new Vector2(0, 0.5f), true))) :
...@@ -155,11 +177,27 @@ public class Mirror : Wall, IBulletInteractor, IBreakable ...@@ -155,11 +177,27 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
if (copyWallGrid.ContainsKey(oppoPos)) MapManager.inst.currentMap.RemoveWall(oppoPos); if (copyWallGrid.ContainsKey(oppoPos)) MapManager.inst.currentMap.RemoveWall(oppoPos);
} }
} }
if (isSameRSide && Mathf.Abs(j) == (MapManager.inst.currentMap.maxMapSize + 1))
{
if (anotherSide)
{
reflectSide *= -1;
anotherSide = false;
break;
}
else
{
anotherSide = true;
reflectSide *= -1;
j = mapRange - reflectSide;
}
}
} }
// check floors // check floors
for (int j = minMapRange; j < maxMapRange; j++) for (int j = mapRange; Mathf.Abs(j) <= (MapManager.inst.currentMap.maxMapSize + 1); j += reflectSide)
{ {
Vector2 crossPoint = dir ? new Vector2(j + 0.5f, iMid) : new Vector2(iMid, j + 0.5f); Vector2 crossPoint = dir ? new Vector2(j + 0.5f * reflectSide, iMid) : new Vector2(iMid, j + 0.5f * reflectSide);
if (IsInRayWeak(parRay, PointToParRay(stPos, crossPoint, true))) if (IsInRayWeak(parRay, PointToParRay(stPos, crossPoint, true)))
{ {
Vector2Int[] floorPoses = Vector2Int[] floorPoses =
...@@ -182,6 +220,22 @@ public class Mirror : Wall, IBulletInteractor, IBreakable ...@@ -182,6 +220,22 @@ public class Mirror : Wall, IBulletInteractor, IBreakable
} }
} }
} }
if (isSameRSide && Mathf.Abs(j) == (MapManager.inst.currentMap.maxMapSize + 1))
{
if (anotherSide)
{
reflectSide *= -1;
anotherSide = false;
break;
}
else
{
anotherSide = true;
reflectSide *= -1;
j = mapRange - reflectSide;
}
}
} }
} }
yield return null; yield return null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment