Aiming syncing fix: aiming angle is calculated from the position of the shoulder towards the cursor (or a position within the collider that's roughly at the shoulder).
This commit is contained in:
@@ -8,7 +8,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
partial class Character
|
partial class Character
|
||||||
{
|
{
|
||||||
public virtual void ClientWrite(NetBuffer msg, object[] extraData = null)
|
public virtual void ClientWrite(NetBuffer msg, object[] extraData = null)
|
||||||
{
|
{
|
||||||
if (GameMain.Server != null) return;
|
if (GameMain.Server != null) return;
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ namespace Barotrauma
|
|||||||
if (aimInput)
|
if (aimInput)
|
||||||
{
|
{
|
||||||
double aimAngle = ((double)msg.ReadUInt16() / 65535.0) * 2.0 * Math.PI;
|
double aimAngle = ((double)msg.ReadUInt16() / 65535.0) * 2.0 * Math.PI;
|
||||||
cursorPosition = (ViewTarget == null ? AnimController.Collider.Position : ViewTarget.Position)
|
cursorPosition = (ViewTarget == null ? AnimController.AimSourcePos : ViewTarget.Position)
|
||||||
+ new Vector2((float)Math.Cos(aimAngle), (float)Math.Sin(aimAngle)) * 60.0f;
|
+ new Vector2((float)Math.Cos(aimAngle), (float)Math.Sin(aimAngle)) * 60.0f;
|
||||||
|
|
||||||
TransformCursorPos();
|
TransformCursorPos();
|
||||||
|
|||||||
@@ -29,6 +29,19 @@ namespace Barotrauma
|
|||||||
get;
|
get;
|
||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector2 AimSourcePos
|
||||||
|
{
|
||||||
|
get { return ConvertUnits.ToDisplayUnits(AimSourceSimPos); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual Vector2 AimSourceSimPos
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Collider.SimPosition;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public AnimController(Character character, XElement element)
|
public AnimController(Character character, XElement element)
|
||||||
: base(character, element)
|
: base(character, element)
|
||||||
|
|||||||
@@ -40,6 +40,26 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override Vector2 AimSourceSimPos
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
float shoulderHeight = Collider.height / 2.0f - 0.1f;
|
||||||
|
if (inWater)
|
||||||
|
{
|
||||||
|
shoulderHeight += 0.4f;
|
||||||
|
}
|
||||||
|
else if (Crouching)
|
||||||
|
{
|
||||||
|
shoulderHeight -= 0.15f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Collider.SimPosition + new Vector2(
|
||||||
|
(float)Math.Sin(-Collider.Rotation),
|
||||||
|
(float)Math.Cos(-Collider.Rotation)) * shoulderHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public HumanoidAnimController(Character character, XElement element)
|
public HumanoidAnimController(Character character, XElement element)
|
||||||
: base(character, element)
|
: base(character, element)
|
||||||
{
|
{
|
||||||
@@ -1012,7 +1032,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
Vector2 mousePos = ConvertUnits.ToSimUnits(character.CursorPosition);
|
Vector2 mousePos = ConvertUnits.ToSimUnits(character.CursorPosition);
|
||||||
|
|
||||||
Vector2 diff = (mousePos - torso.SimPosition) * Dir;
|
Vector2 diff = (mousePos - AimSourceSimPos) * Dir;
|
||||||
|
|
||||||
holdAngle = MathUtils.VectorToAngle(new Vector2(diff.X, diff.Y * Dir)) - torso.body.Rotation * Dir;
|
holdAngle = MathUtils.VectorToAngle(new Vector2(diff.X, diff.Y * Dir)) - torso.body.Rotation * Dir;
|
||||||
|
|
||||||
@@ -1064,12 +1084,8 @@ namespace Barotrauma
|
|||||||
leftHand.Disabled = true;
|
leftHand.Disabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
itemPos.X = itemPos.X * Dir;
|
||||||
itemPos.X = itemPos.X * Dir;
|
transformedHoldPos += Vector2.Transform(itemPos, Matrix.CreateRotationZ(itemAngle));
|
||||||
|
|
||||||
Matrix torsoTransform = Matrix.CreateRotationZ(itemAngle);
|
|
||||||
|
|
||||||
transformedHoldPos += Vector2.Transform(itemPos, torsoTransform);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
item.body.ResetDynamics();
|
item.body.ResetDynamics();
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ namespace Barotrauma
|
|||||||
dequeuedInput = memInput[memInput.Count - 1].states;
|
dequeuedInput = memInput[memInput.Count - 1].states;
|
||||||
|
|
||||||
double aimAngle = ((double)memInput[memInput.Count - 1].intAim / 65535.0) * 2.0 * Math.PI;
|
double aimAngle = ((double)memInput[memInput.Count - 1].intAim / 65535.0) * 2.0 * Math.PI;
|
||||||
cursorPosition = (ViewTarget == null ? AnimController.Collider.Position : ViewTarget.Position)
|
cursorPosition = (ViewTarget == null ? AnimController.AimSourcePos : ViewTarget.Position)
|
||||||
+ new Vector2((float)Math.Cos(aimAngle), (float)Math.Sin(aimAngle)) * 60.0f;
|
+ new Vector2((float)Math.Cos(aimAngle), (float)Math.Sin(aimAngle)) * 60.0f;
|
||||||
|
|
||||||
var closestEntity = Entity.FindEntityByID(memInput[memInput.Count - 1].interact);
|
var closestEntity = Entity.FindEntityByID(memInput[memInput.Count - 1].interact);
|
||||||
@@ -198,7 +198,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (AnimController.TargetDir == Direction.Left) newInput |= InputNetFlags.FacingLeft;
|
if (AnimController.TargetDir == Direction.Left) newInput |= InputNetFlags.FacingLeft;
|
||||||
|
|
||||||
Vector2 relativeCursorPos = cursorPosition - (ViewTarget == null ? AnimController.Collider.Position : ViewTarget.Position);
|
Vector2 relativeCursorPos = cursorPosition - (ViewTarget == null ? AnimController.AimSourcePos : ViewTarget.Position);
|
||||||
relativeCursorPos.Normalize();
|
relativeCursorPos.Normalize();
|
||||||
UInt16 intAngle = (UInt16)(65535.0 * Math.Atan2(relativeCursorPos.Y, relativeCursorPos.X) / (2.0 * Math.PI));
|
UInt16 intAngle = (UInt16)(65535.0 * Math.Atan2(relativeCursorPos.Y, relativeCursorPos.X) / (2.0 * Math.PI));
|
||||||
|
|
||||||
@@ -418,7 +418,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (aiming)
|
if (aiming)
|
||||||
{
|
{
|
||||||
Vector2 relativeCursorPos = cursorPosition - (ViewTarget == null ? AnimController.Collider.Position : ViewTarget.Position);
|
Vector2 relativeCursorPos = cursorPosition - (ViewTarget == null ? AnimController.AimSourcePos : ViewTarget.Position);
|
||||||
tempBuffer.Write((UInt16)(65535.0 * Math.Atan2(relativeCursorPos.Y, relativeCursorPos.X) / (2.0 * Math.PI)));
|
tempBuffer.Write((UInt16)(65535.0 * Math.Atan2(relativeCursorPos.Y, relativeCursorPos.X) / (2.0 * Math.PI)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user