Setting ragdoll position without limbs going through walls, rotating entire ragdoll, using combined network messages client->server, fixed fabricators
This commit is contained in:
@@ -91,19 +91,19 @@ namespace Barotrauma
|
||||
return true;
|
||||
case NetworkEventType.ImportantEntityUpdate:
|
||||
int i = 0;
|
||||
foreach (Limb limb in AnimController.Limbs)
|
||||
{
|
||||
if (limb.ignoreCollisions) continue;
|
||||
//foreach (Limb limb in AnimController.Limbs)
|
||||
//{
|
||||
//if (RefLimb.ignoreCollisions) continue;
|
||||
|
||||
if (limb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return false;
|
||||
if (AnimController.RefLimb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return false;
|
||||
|
||||
message.WriteRangedSingle(limb.body.SimPosition.X, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
|
||||
message.WriteRangedSingle(limb.body.SimPosition.Y, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
|
||||
message.WriteRangedSingle(AnimController.RefLimb.SimPosition.X, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
|
||||
message.WriteRangedSingle(AnimController.RefLimb.SimPosition.Y, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
|
||||
|
||||
|
||||
message.Write(limb.body.Rotation);
|
||||
i++;
|
||||
}
|
||||
message.Write(AnimController.RefLimb.Rotation);
|
||||
// i++;
|
||||
//}
|
||||
|
||||
message.WriteRangedSingle(MathHelper.Clamp(AnimController.StunTimer, 0.0f, 60.0f), 0.0f, 60.0f, 8);
|
||||
message.Write((byte)((health / maxHealth) * 255.0f));
|
||||
@@ -126,8 +126,9 @@ namespace Barotrauma
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message)
|
||||
public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, out object data)
|
||||
{
|
||||
data = null;
|
||||
Enabled = true;
|
||||
|
||||
switch (type)
|
||||
@@ -136,12 +137,12 @@ namespace Barotrauma
|
||||
Kill(CauseOfDeath.Damage, true);
|
||||
return;
|
||||
case NetworkEventType.ImportantEntityUpdate:
|
||||
foreach (Limb limb in AnimController.Limbs)
|
||||
{
|
||||
if (limb.ignoreCollisions) continue;
|
||||
//foreach (Limb limb in AnimController.Limbs)
|
||||
//{
|
||||
// if (limb.ignoreCollisions) continue;
|
||||
|
||||
Vector2 limbPos = limb.SimPosition;
|
||||
float rotation = limb.Rotation;
|
||||
Vector2 limbPos = AnimController.RefLimb.SimPosition;
|
||||
float rotation = AnimController.RefLimb.Rotation;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -155,14 +156,14 @@ namespace Barotrauma
|
||||
return;
|
||||
}
|
||||
|
||||
if (limb.body != null)
|
||||
if (AnimController.RefLimb.body != null)
|
||||
{
|
||||
limb.body.TargetVelocity = limb.body.LinearVelocity;
|
||||
limb.body.TargetPosition = limbPos;// +vel * (float)(deltaTime / 60.0);
|
||||
limb.body.TargetRotation = rotation;// +angularVel * (float)(deltaTime / 60.0);
|
||||
limb.body.TargetAngularVelocity = limb.body.AngularVelocity;
|
||||
//AnimController.RefLimb.body.TargetVelocity = limb.body.LinearVelocity;
|
||||
AnimController.RefLimb.body.TargetPosition = limbPos;// +vel * (float)(deltaTime / 60.0);
|
||||
AnimController.RefLimb.body.TargetRotation = rotation;// +angularVel * (float)(deltaTime / 60.0);
|
||||
//limb.body.TargetAngularVelocity = limb.body.AngularVelocity;
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
||||
float newStunTimer = 0.0f, newHealth = 0.0f;
|
||||
|
||||
|
||||
@@ -443,6 +443,12 @@ namespace Barotrauma
|
||||
return keys[(int)inputType].Held;
|
||||
}
|
||||
|
||||
public void ClearInput(InputType inputType)
|
||||
{
|
||||
keys[(int)inputType].Hit = false;
|
||||
keys[(int)inputType].Held = false;
|
||||
}
|
||||
|
||||
public void ClearInputs()
|
||||
{
|
||||
foreach (Key key in keys)
|
||||
@@ -577,10 +583,13 @@ namespace Barotrauma
|
||||
|
||||
public void CreateUpdateNetworkEvent(bool isClient)
|
||||
{
|
||||
new NetworkEvent(importantUpdateTimer <= 0 ? NetworkEventType.ImportantEntityUpdate : NetworkEventType.EntityUpdate, ID, isClient);
|
||||
//new NetworkEvent(importantUpdateTimer <= 0 ? NetworkEventType.ImportantEntityUpdate : NetworkEventType.EntityUpdate, ID, isClient);
|
||||
|
||||
importantUpdateTimer -= 1;
|
||||
if (importantUpdateTimer < 0) importantUpdateTimer = (this is AICharacter) ? 40 : 25;
|
||||
new NetworkEvent(NetworkEventType.EntityUpdate, ID, isClient);
|
||||
|
||||
|
||||
//importantUpdateTimer -= 1;
|
||||
//if (importantUpdateTimer < 0) importantUpdateTimer = (this is AICharacter) ? 30 : 10;
|
||||
}
|
||||
|
||||
|
||||
@@ -1301,9 +1310,10 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message)
|
||||
public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, out object data)
|
||||
{
|
||||
Enabled = true;
|
||||
data = null;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
@@ -1315,6 +1325,8 @@ namespace Barotrauma
|
||||
bool pickHit = message.ReadBoolean();
|
||||
bool actionHit = message.ReadBoolean();
|
||||
|
||||
data = new int[] { (int)itemId, pickHit ? 1 : 0, actionHit ? 1: 0 };
|
||||
|
||||
System.Diagnostics.Debug.WriteLine("item id: "+itemId);
|
||||
|
||||
Item item = FindEntityByID(itemId) as Item;
|
||||
@@ -1323,6 +1335,8 @@ namespace Barotrauma
|
||||
return;
|
||||
case NetworkEventType.SelectCharacter:
|
||||
ushort characterId = message.ReadUInt16();
|
||||
data = characterId;
|
||||
|
||||
if (characterId==0)
|
||||
{
|
||||
DeselectCharacter(false);
|
||||
@@ -1352,6 +1366,8 @@ namespace Barotrauma
|
||||
causeOfDeath = CauseOfDeath.Damage;
|
||||
}
|
||||
|
||||
data = causeOfDeath;
|
||||
|
||||
if (causeOfDeath==CauseOfDeath.Pressure)
|
||||
{
|
||||
Implode(true);
|
||||
|
||||
@@ -649,9 +649,63 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
limb.Update(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetPosition(Vector2 simPosition)
|
||||
{
|
||||
Vector2 moveAmount = simPosition - refLimb.SimPosition;
|
||||
|
||||
foreach (Limb limb in Limbs)
|
||||
{
|
||||
if (limb==refLimb)
|
||||
{
|
||||
limb.body.SetTransform(simPosition, limb.Rotation);
|
||||
continue;
|
||||
}
|
||||
|
||||
//check visibility from the new position of RefLimb to the new position of this limb
|
||||
Vector2 movePos = limb.SimPosition + moveAmount;
|
||||
|
||||
TrySetLimbPosition(limb, simPosition, movePos);
|
||||
}
|
||||
}
|
||||
|
||||
private void TrySetLimbPosition(Limb limb, Vector2 original, Vector2 simPosition)
|
||||
{
|
||||
if (original == simPosition) return;
|
||||
|
||||
Body body = Submarine.CheckVisibility(original, simPosition);
|
||||
Vector2 movePos = simPosition;
|
||||
|
||||
//if there's something in between the limbs
|
||||
if (body != null)
|
||||
{
|
||||
//move the limb close to the position where the raycast hit something
|
||||
movePos = original + ((simPosition - original) * Submarine.LastPickedFraction * 0.9f);
|
||||
}
|
||||
|
||||
limb.body.SetTransform(movePos, limb.Rotation);
|
||||
}
|
||||
|
||||
public void SetRotation(float rotation)
|
||||
{
|
||||
float rotateAmount = rotation - refLimb.Rotation;
|
||||
|
||||
Matrix rotationMatrix = Matrix.CreateRotationZ(rotateAmount);
|
||||
|
||||
refLimb.body.SetTransform(refLimb.SimPosition, rotation);
|
||||
|
||||
foreach (Limb limb in Limbs)
|
||||
{
|
||||
if (limb == refLimb) continue;
|
||||
|
||||
Vector2 newPos = limb.SimPosition - refLimb.SimPosition;
|
||||
newPos = Vector2.Transform(newPos, rotationMatrix);
|
||||
|
||||
TrySetLimbPosition(limb, refLimb.SimPosition, refLimb.SimPosition + newPos);
|
||||
limb.body.SetTransform(limb.SimPosition, limb.Rotation + rotateAmount);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void UpdateNetPlayerPosition()
|
||||
@@ -708,22 +762,26 @@ namespace Barotrauma
|
||||
|
||||
if (resetAll)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("reset ragdoll limb positions");
|
||||
System.Diagnostics.Debug.WriteLine("reset ragdoll limb positions");
|
||||
|
||||
foreach (Limb limb in Limbs)
|
||||
{
|
||||
//if (limb.body.TargetPosition == Vector2.Zero)
|
||||
//{
|
||||
limb.body.SetTransform(limb.body.SimPosition + diff, limb.body.Rotation);
|
||||
//continue;
|
||||
//}
|
||||
SetPosition(refLimb.body.TargetPosition);
|
||||
|
||||
//limb.body.LinearVelocity = limb.body.TargetVelocity;
|
||||
//limb.body.AngularVelocity = limb.body.TargetAngularVelocity;
|
||||
if (character is AICharacter) SetRotation(refLimb.body.TargetRotation);
|
||||
|
||||
//limb.body.SetTransform(limb.body.TargetPosition, limb.body.TargetRotation);
|
||||
limb.body.TargetPosition = Vector2.Zero;
|
||||
}
|
||||
//foreach (Limb limb in Limbs)
|
||||
//{
|
||||
// if (limb.body.TargetPosition == Vector2.Zero)
|
||||
// {
|
||||
// limb.body.SetTransform(limb.body.SimPosition + diff, limb.body.Rotation);
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// limb.body.LinearVelocity = limb.body.TargetVelocity;
|
||||
// limb.body.AngularVelocity = limb.body.TargetAngularVelocity;
|
||||
|
||||
// limb.body.SetTransform(limb.body.TargetPosition, limb.body.TargetRotation);
|
||||
// limb.body.TargetPosition = Vector2.Zero;
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user