Fixed the door collision bug at docking ports
This commit is contained in:
@@ -549,7 +549,7 @@ namespace Barotrauma
|
||||
|
||||
if (bodyShapeTexture == null)
|
||||
{
|
||||
switch (body.bodyShape)
|
||||
switch (body.BodyShape)
|
||||
{
|
||||
case PhysicsBody.Shape.Rectangle:
|
||||
bodyShapeTexture = GUI.CreateRectangle(
|
||||
|
||||
@@ -33,8 +33,12 @@ namespace Barotrauma.Items.Components
|
||||
private Hull[] hulls;
|
||||
private ushort?[] hullIds;
|
||||
|
||||
private Door door;
|
||||
|
||||
private Body[] bodies;
|
||||
|
||||
private Body doorBody;
|
||||
|
||||
private Gap gap;
|
||||
private ushort? gapId;
|
||||
|
||||
@@ -259,6 +263,21 @@ namespace Barotrauma.Items.Components
|
||||
wire.Connect(recipient, false);
|
||||
}
|
||||
|
||||
private void CreateDoorBody()
|
||||
{
|
||||
doorBody = BodyFactory.CreateRectangle(GameMain.World,
|
||||
dockingTarget.door.Body.width,
|
||||
dockingTarget.door.Body.height,
|
||||
1.0f,
|
||||
dockingTarget.door);
|
||||
|
||||
doorBody.CollisionCategories = Physics.CollisionWall;
|
||||
doorBody.BodyType = BodyType.Static;
|
||||
doorBody.SetTransform(
|
||||
ConvertUnits.ToSimUnits(item.Position + (dockingTarget.door.Item.WorldPosition - item.WorldPosition)),
|
||||
0.0f);
|
||||
}
|
||||
|
||||
private void CreateHull()
|
||||
{
|
||||
var hullRects = new Rectangle[] { item.WorldRect, dockingTarget.item.WorldRect };
|
||||
@@ -266,6 +285,17 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
hulls = new Hull[2];
|
||||
bodies = new Body[4];
|
||||
|
||||
if (dockingTarget.door != null)
|
||||
{
|
||||
CreateDoorBody();
|
||||
}
|
||||
|
||||
if (door != null)
|
||||
{
|
||||
dockingTarget.CreateDoorBody();
|
||||
}
|
||||
|
||||
if (IsHorizontal)
|
||||
{
|
||||
if (hullRects[0].Center.X > hullRects[1].Center.X)
|
||||
@@ -277,7 +307,7 @@ namespace Barotrauma.Items.Components
|
||||
hullRects[0] = new Rectangle(hullRects[0].Center.X, hullRects[0].Y, ((int)DockedDistance / 2), hullRects[0].Height);
|
||||
hullRects[1] = new Rectangle(hullRects[1].Center.X - ((int)DockedDistance / 2), hullRects[1].Y, ((int)DockedDistance / 2), hullRects[1].Height);
|
||||
|
||||
for (int i = 0; i < 2;i++ )
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
hullRects[i].Location -= (subs[i].WorldPosition - subs[i].HiddenSubPosition).ToPoint();
|
||||
hulls[i] = new Hull(MapEntityPrefab.list.Find(m => m.Name == "Hull"), hullRects[i], subs[i]);
|
||||
@@ -304,8 +334,6 @@ namespace Barotrauma.Items.Components
|
||||
gap.linkedTo.Add(hulls[1]);
|
||||
gap.linkedTo.Add(hulls[0]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -325,13 +353,6 @@ namespace Barotrauma.Items.Components
|
||||
hulls[i].AddToGrid(subs[i]);
|
||||
|
||||
if (hullIds[i] != null) hulls[i].ID = (ushort)hullIds[i];
|
||||
|
||||
//for (int j = 0; j < 2; j++)
|
||||
//{
|
||||
// bodies[i + j * 2] = BodyFactory.CreateEdge(GameMain.World,
|
||||
// ConvertUnits.ToSimUnits(new Vector2(hullRects[i].X + hullRects[i].Width * j, hullRects[i].Y)),
|
||||
// ConvertUnits.ToSimUnits(new Vector2(hullRects[i].X + hullRects[i].Width * j, hullRects[i].Y-hullRects[i].Height)));
|
||||
//}
|
||||
}
|
||||
|
||||
gap = new Gap(new Rectangle(hullRects[0].X, hullRects[0].Y+2, hullRects[0].Width, 4), false, subs[0]);
|
||||
@@ -368,8 +389,6 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
body.CollisionCategories = Physics.CollisionWall;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void Undock()
|
||||
@@ -408,6 +427,12 @@ namespace Barotrauma.Items.Components
|
||||
dockingTarget.Undock();
|
||||
dockingTarget = null;
|
||||
|
||||
if (doorBody != null)
|
||||
{
|
||||
GameMain.World.RemoveBody(doorBody);
|
||||
doorBody = null;
|
||||
}
|
||||
|
||||
var wire = item.GetComponent<Wire>();
|
||||
if (wire != null)
|
||||
{
|
||||
@@ -479,8 +504,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
PlaySound(ActionType.OnSecondaryUse, item.WorldPosition);
|
||||
|
||||
ConnectWireBetweenPorts();
|
||||
|
||||
ConnectWireBetweenPorts();
|
||||
|
||||
CreateJoint(true);
|
||||
|
||||
@@ -495,6 +519,11 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dockingTarget.door != null && doorBody != null)
|
||||
{
|
||||
doorBody.Enabled = dockingTarget.door.Body.Enabled;
|
||||
}
|
||||
|
||||
item.SendSignal(0, "1", "state_out");
|
||||
|
||||
dockingState = MathHelper.Lerp(dockingState, 1.0f, deltaTime * 10.0f);
|
||||
@@ -564,11 +593,24 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public override void OnMapLoaded()
|
||||
{
|
||||
foreach (Item it in Item.ItemList)
|
||||
{
|
||||
if (it.Submarine != item.Submarine) continue;
|
||||
|
||||
var doorComponent = it.GetComponent<Door>();
|
||||
if (doorComponent == null) continue;
|
||||
|
||||
if (Vector2.Distance(item.Position, doorComponent.Item.Position) < Submarine.GridSize.X)
|
||||
{
|
||||
this.door = doorComponent;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!item.linkedTo.Any()) return;
|
||||
|
||||
foreach (MapEntity entity in item.linkedTo)
|
||||
{
|
||||
|
||||
var hull = entity as Hull;
|
||||
if (hull != null)
|
||||
{
|
||||
@@ -651,9 +693,12 @@ namespace Barotrauma.Items.Components
|
||||
hullIds[1] = message.ReadUInt16();
|
||||
|
||||
gapId = message.ReadUInt16();
|
||||
if (hulls != null)
|
||||
{
|
||||
if (hulls[0] != null) hulls[0].ID = (ushort)hullIds[0];
|
||||
if (hulls[1] != null) hulls[1].ID = (ushort)hullIds[1];
|
||||
}
|
||||
|
||||
if (hulls[0] != null) hulls[0].ID = (ushort)hullIds[0];
|
||||
if (hulls[1] != null) hulls[1].ID = (ushort)hullIds[1];
|
||||
|
||||
if (gap != null) gap.ID = (ushort)gapId;
|
||||
|
||||
|
||||
@@ -33,6 +33,11 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private float lastReceivedMessage;
|
||||
|
||||
public PhysicsBody Body
|
||||
{
|
||||
get { return body; }
|
||||
}
|
||||
|
||||
private float stuck;
|
||||
public float Stuck
|
||||
{
|
||||
@@ -145,13 +150,14 @@ namespace Barotrauma.Items.Components
|
||||
(int)doorSprite.size.X,
|
||||
(int)doorSprite.size.Y);
|
||||
|
||||
body = new PhysicsBody(BodyFactory.CreateRectangle(GameMain.World,
|
||||
body = new PhysicsBody(
|
||||
ConvertUnits.ToSimUnits(Math.Max(doorRect.Width, 1)),
|
||||
ConvertUnits.ToSimUnits(Math.Max(doorRect.Height, 1)),
|
||||
1.5f));
|
||||
0.0f,
|
||||
1.5f);
|
||||
|
||||
body.CollisionCategories = Physics.CollisionWall;
|
||||
body.UserData = item;
|
||||
body.CollisionCategories = Physics.CollisionWall;
|
||||
body.BodyType = BodyType.Static;
|
||||
body.SetTransform(
|
||||
ConvertUnits.ToSimUnits(new Vector2(doorRect.Center.X, doorRect.Y - doorRect.Height / 2)),
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace Barotrauma.Items.Components
|
||||
ropeList[i].CollisionCategories = Physics.CollisionItem;
|
||||
ropeList[i].CollidesWith = Physics.CollisionWall;
|
||||
|
||||
ropeBodies[i] = new PhysicsBody(ropeList[i]);
|
||||
//ropeBodies[i] = new PhysicsBody(ropeList[i]);
|
||||
}
|
||||
|
||||
List<RevoluteJoint> joints = PathManager.AttachBodiesWithRevoluteJoint(GameMain.World, ropeList,
|
||||
|
||||
@@ -42,8 +42,8 @@ namespace Barotrauma
|
||||
private set;
|
||||
}
|
||||
|
||||
public readonly Shape bodyShape;
|
||||
public readonly float height, width, radius;
|
||||
private Shape bodyShape;
|
||||
public float height, width, radius;
|
||||
|
||||
private float density;
|
||||
|
||||
@@ -53,6 +53,11 @@ namespace Barotrauma
|
||||
|
||||
Vector2 offsetFromTargetPos;
|
||||
|
||||
public Shape BodyShape
|
||||
{
|
||||
get { return bodyShape; }
|
||||
}
|
||||
|
||||
public Vector2 TargetPosition
|
||||
{
|
||||
get { return targetPosition; }
|
||||
@@ -192,14 +197,12 @@ namespace Barotrauma
|
||||
{
|
||||
}
|
||||
|
||||
public PhysicsBody(Body body)
|
||||
{
|
||||
this.body = body;
|
||||
|
||||
density = 10.0f;
|
||||
|
||||
public PhysicsBody(float width, float height, float radius, float density)
|
||||
{
|
||||
CreateBody(width, height, radius, density);
|
||||
|
||||
dir = 1.0f;
|
||||
|
||||
|
||||
LastSentPosition = body.Position;
|
||||
|
||||
list.Add(this);
|
||||
@@ -213,29 +216,7 @@ namespace Barotrauma
|
||||
|
||||
density = ToolBox.GetAttributeFloat(element, "density", 10.0f);
|
||||
|
||||
if (width != 0.0f && height != 0.0f)
|
||||
{
|
||||
body = BodyFactory.CreateRectangle(GameMain.World, width, height, density);
|
||||
bodyShape = Shape.Rectangle;
|
||||
}
|
||||
else if (radius != 0.0f && height != 0.0f)
|
||||
{
|
||||
body = BodyFactory.CreateCapsule(GameMain.World, height, radius, density);
|
||||
bodyShape = Shape.Capsule;
|
||||
}
|
||||
else if (radius != 0.0f)
|
||||
{
|
||||
body = BodyFactory.CreateCircle(GameMain.World, radius, density);
|
||||
bodyShape = Shape.Circle;
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugConsole.ThrowError("Invalid body dimensions in " + element);
|
||||
}
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.radius = radius;
|
||||
CreateBody(width, height, radius, density);
|
||||
|
||||
dir = 1.0f;
|
||||
|
||||
@@ -257,6 +238,33 @@ namespace Barotrauma
|
||||
list.Add(this);
|
||||
}
|
||||
|
||||
private void CreateBody(float width, float height, float radius, float density)
|
||||
{
|
||||
if (width != 0.0f && height != 0.0f)
|
||||
{
|
||||
body = BodyFactory.CreateRectangle(GameMain.World, width, height, density);
|
||||
bodyShape = Shape.Rectangle;
|
||||
}
|
||||
else if (radius != 0.0f && height != 0.0f)
|
||||
{
|
||||
body = BodyFactory.CreateCapsule(GameMain.World, height, radius, density);
|
||||
bodyShape = Shape.Capsule;
|
||||
}
|
||||
else if (radius != 0.0f)
|
||||
{
|
||||
body = BodyFactory.CreateCircle(GameMain.World, radius, density);
|
||||
bodyShape = Shape.Circle;
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugConsole.ThrowError("Invalid physics body dimensions (width: " + width + ", height: " + height + ", radius: " + radius + ")");
|
||||
}
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
public void ResetDynamics()
|
||||
{
|
||||
body.ResetDynamics();
|
||||
|
||||
Reference in New Issue
Block a user