Accounting for gravity flip GRAHHHH
This commit is contained in:
1 parent
5f4ec73ec2
commit
803bde708d
5 files changed
+48
-11
No files matched your search
@@ -82,7 +82,8 @@ namespace CalamityMod.Items.Weapons.Melee
|
||||
player.ChangeDir(-1);
|
||||
}
|
||||
|
||||
CalamityUtils.CleanHoldStyle(player, player.compositeFrontArm.rotation + MathHelper.PiOver2, player.GetFrontHandPosition(player.compositeFrontArm.stretch, player.compositeFrontArm.rotation).Floor(), new Vector2(42, 34), new Vector2(-15, 11));
|
||||
|
||||
CalamityUtils.CleanHoldStyle(player, player.compositeFrontArm.rotation + MathHelper.PiOver2 * player.gravDir, player.GetFrontHandPositionImproved(player.compositeFrontArm), new Vector2(42, 34), new Vector2(-15, 11));
|
||||
}
|
||||
|
||||
|
||||
@@ -108,8 +109,8 @@ namespace CalamityMod.Items.Weapons.Melee
|
||||
armPointingDirection = -MathHelper.Pi + MathHelper.PiOver4 * Utils.GetLerpValue(-MathHelper.Pi, -MathHelper.PiOver4, armPointingDirection, true);
|
||||
}
|
||||
|
||||
player.SetCompositeArmBack(true, Player.CompositeArmStretchAmount.Full, armPointingDirection - MathHelper.PiOver2);
|
||||
player.SetCompositeArmFront(true, Player.CompositeArmStretchAmount.Full, armPointingDirection - MathHelper.PiOver2);
|
||||
player.SetCompositeArmBack(true, Player.CompositeArmStretchAmount.Full, armPointingDirection * player.gravDir - MathHelper.PiOver2);
|
||||
player.SetCompositeArmFront(true, Player.CompositeArmStretchAmount.Full, armPointingDirection * player.gravDir - MathHelper.PiOver2);
|
||||
}
|
||||
|
||||
public override void HoldStyle(Player player, Rectangle heldItemFrame)
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace CalamityMod.Items.Weapons.Ranged
|
||||
velocity = velocity.RotatedByRandom(0.01f);
|
||||
}
|
||||
|
||||
public static Vector2 getPlayerMouth(Player player) => player.MountedCenter - 5f * Vector2.UnitY + Vector2.UnitX * 6f * player.direction;
|
||||
public static Vector2 getPlayerMouth(Player player) => player.MountedCenter - 5f * Vector2.UnitY * player.gravDir + Vector2.UnitX * 6f * player.direction;
|
||||
public static Vector2 getPlayerShoulder(Player player) => player.MountedCenter - Vector2.UnitX * 4f * player.direction;
|
||||
|
||||
public void SetItemInHand(Player player, Rectangle heldItemFrame)
|
||||
@@ -73,7 +73,7 @@ namespace CalamityMod.Items.Weapons.Ranged
|
||||
Vector2 playerMouth = getPlayerMouth(player);
|
||||
|
||||
Vector2 playerToCursor = (player.Calamity().mouseWorld - playerMouth).SafeNormalize(Vector2.UnitX);
|
||||
float pointingDirection = (playerToCursor.ToRotation() + MathHelper.PiOver4 / 3f * player.direction);
|
||||
float pointingDirection = (playerToCursor.ToRotation() + MathHelper.PiOver4 / 3f * player.direction * player.gravDir);
|
||||
|
||||
CalamityUtils.CleanHoldStyle(player, pointingDirection, playerMouth, new Vector2(50, 18), new Vector2(-23, 6));
|
||||
}
|
||||
@@ -91,9 +91,9 @@ namespace CalamityMod.Items.Weapons.Ranged
|
||||
float frontArmDirection = (playerMouth + mouthToCursor * 25f - getPlayerShoulder(player)).ToRotation();
|
||||
|
||||
if (frontArm)
|
||||
player.SetCompositeArmFront(true, Player.CompositeArmStretchAmount.Full, frontArmDirection - MathHelper.PiOver2);
|
||||
player.SetCompositeArmFront(true, Player.CompositeArmStretchAmount.Full, frontArmDirection * player.gravDir - MathHelper.PiOver2);
|
||||
|
||||
player.SetCompositeArmBack(true, Player.CompositeArmStretchAmount.Full, backArmDirection - MathHelper.PiOver2);
|
||||
player.SetCompositeArmBack(true, Player.CompositeArmStretchAmount.Full, backArmDirection * player.gravDir - MathHelper.PiOver2);
|
||||
}
|
||||
|
||||
public override void HoldStyle(Player player, Rectangle heldItemFrame)
|
||||
|
||||
@@ -52,12 +52,12 @@ namespace CalamityMod.Projectiles.Ranged
|
||||
|
||||
if (ChargingUp)
|
||||
{
|
||||
float bubbleRotation = Owner.itemRotation - MathHelper.PiOver4 / 3f * Owner.direction;
|
||||
float bubbleRotation = Owner.itemRotation - MathHelper.PiOver4 / 3f * Owner.direction * Owner.gravDir;
|
||||
if (Owner.direction < 0)
|
||||
bubbleRotation += MathHelper.Pi;
|
||||
|
||||
|
||||
Vector2 bubblePosition = ReedBlowgun.getPlayerMouth(Owner) + (bubbleRotation + MathHelper.PiOver4 / 15f * Owner.direction).ToRotationVector2() * 48f;
|
||||
Vector2 bubblePosition = ReedBlowgun.getPlayerMouth(Owner) + (bubbleRotation + MathHelper.PiOver4 / 15f * Owner.direction * Owner.gravDir).ToRotationVector2() * 48f;
|
||||
|
||||
Projectile.Center = bubblePosition;
|
||||
Projectile.velocity = Vector2.UnitX.RotatedBy(bubbleRotation) * Projectile.velocity.Length();
|
||||
|
||||
@@ -70,8 +70,8 @@ namespace CalamityMod.Projectiles.Rogue
|
||||
|
||||
Owner.heldProj = Projectile.whoAmI;
|
||||
|
||||
Projectile.Center = Owner.MountedCenter + Vector2.UnitY.RotatedBy(armRotation) * -40f;
|
||||
Projectile.rotation = -MathHelper.PiOver2 + armRotation;
|
||||
Projectile.Center = Owner.MountedCenter + Vector2.UnitY.RotatedBy(armRotation * Owner.gravDir) * -40f * Owner.gravDir;
|
||||
Projectile.rotation = (-MathHelper.PiOver2 + armRotation) * Owner.gravDir;
|
||||
|
||||
Owner.SetCompositeArmFront(true, Player.CompositeArmStretchAmount.Full, MathHelper.Pi + armRotation);
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ using Terraria.ModLoader;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using static Terraria.ModLoader.ModContent;
|
||||
using static Terraria.Player;
|
||||
|
||||
namespace CalamityMod
|
||||
{
|
||||
@@ -488,6 +489,39 @@ namespace CalamityMod
|
||||
#endregion
|
||||
|
||||
#region Arms Control
|
||||
|
||||
/// <summary>
|
||||
/// The exact same thing as Player.GetFrontHandPosition() except it properly accounts for gravity swaps instead of requiring the coders to do it manually afterwards.
|
||||
/// Additionally, it simply takes in the arm data instead of asking for the rotation and stretch separately.
|
||||
/// </summary>
|
||||
public static Vector2 GetFrontHandPositionImproved(this Player player, CompositeArmData arm)
|
||||
{
|
||||
Vector2 position = player.GetFrontHandPosition(arm.stretch, arm.rotation * player.gravDir).Floor();
|
||||
|
||||
if (player.gravDir == -1f)
|
||||
{
|
||||
position.Y = player.position.Y + (float)player.height + (player.position.Y - position.Y);
|
||||
}
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The exact same thing as Player.GetBackHandPosition() except it properly accounts for gravity swaps instead of requiring the coders to do it manually afterwards.
|
||||
/// Additionally, it simply takes in the arm data instead of asking for the rotation and stretch separately.
|
||||
/// </summary>
|
||||
public static Vector2 GetBackHandPositionImproved(this Player player, CompositeArmData arm)
|
||||
{
|
||||
Vector2 position = player.GetBackHandPosition(arm.stretch, arm.rotation * player.gravDir).Floor();
|
||||
|
||||
if (player.gravDir == -1f)
|
||||
{
|
||||
position.Y = player.position.Y + (float)player.height + (player.position.Y - position.Y);
|
||||
}
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Properly sets the player's held item rotation and position by doing the annoying math for you, since vanilla decided to be wholly inconsistent about it!
|
||||
/// This all assumes the player is facing right. All the flip stuff is automatically handled in here
|
||||
@@ -508,6 +542,8 @@ namespace CalamityMod
|
||||
Vector2 origin = rotationOriginFromCenter.Value;
|
||||
//Flip the origin's X position, since the sprite will be flipped if the player faces left.
|
||||
origin.X *= player.direction;
|
||||
//Additionally, flip the origin's Y position in case the player is in reverse gravity.
|
||||
origin.Y *= player.gravDir;
|
||||
|
||||
player.itemRotation = desiredRotation;
|
||||
|
||||
|
||||
Reference in new issue
Block a user