From 2f060b9398f05bbbeb82145aef34d5afeb52601b Mon Sep 17 00:00:00 2001 From: Dominic Date: Sat, 26 Jun 2021 13:16:46 -0500 Subject: [PATCH] DirectionTo safening --- Items/Weapons/Magic/ElementalRay.cs | 2 +- Items/Weapons/Melee/Violence.cs | 9 ++------- Projectiles/Magic/ApotheosisWorm.cs | 2 +- Projectiles/Magic/FabRay.cs | 2 +- Projectiles/Magic/RainbowRocket.cs | 2 +- Projectiles/Magic/RedirectingFire.cs | 2 +- Projectiles/Melee/ViolenceSlashProjectile.cs | 2 +- Projectiles/Melee/ViolenceThrownProjectile.cs | 6 +++--- Projectiles/Ranged/CondemnationArrowHoming.cs | 2 +- Projectiles/Ranged/PrismComet.cs | 2 +- Projectiles/Ranged/PrismMine.cs | 2 +- Projectiles/Rogue/PrismRocket.cs | 2 +- Projectiles/Rogue/SacrificeProjectile.cs | 2 +- Projectiles/Summon/DaedalusGolem.cs | 6 +++--- Projectiles/Summon/EyeOfNightSummon.cs | 4 ++-- Projectiles/Summon/FleshBallMinion.cs | 2 +- Projectiles/Summon/FlowersOfMortalityPetal.cs | 2 +- Projectiles/Summon/LostSoulGiant.cs | 2 +- Projectiles/Summon/MortalityBeam.cs | 2 +- Projectiles/Summon/SeekerSummonProj.cs | 6 +++--- Projectiles/Summon/SlimePuppet.cs | 6 +++--- Projectiles/Summon/ViridVanguardBlade.cs | 2 +- Projectiles/Summon/WitherBlossom.cs | 2 +- Projectiles/Summon/WitherBolt.cs | 2 +- 24 files changed, 34 insertions(+), 39 deletions(-) diff --git a/Items/Weapons/Magic/ElementalRay.cs b/Items/Weapons/Magic/ElementalRay.cs index 3b06d836ce..2c6d165a4e 100644 --- a/Items/Weapons/Magic/ElementalRay.cs +++ b/Items/Weapons/Magic/ElementalRay.cs @@ -67,7 +67,7 @@ namespace CalamityMod.Items.Weapons.Magic return false; } - Vector2 spawnOffset = player.DirectionTo(Main.MouseWorld).RotatedBy(offsetAngle) * -Main.rand.NextFloat(40f, 96f); + Vector2 spawnOffset = player.SafeDirectionTo(Main.MouseWorld, Vector2.UnitY).RotatedBy(offsetAngle) * -Main.rand.NextFloat(40f, 96f); Vector2 shootDirection = (Main.MouseWorld - (position + spawnOffset)).SafeNormalize(Vector2.UnitX * player.direction); int beam = Projectile.NewProjectile(position + spawnOffset, shootDirection * shootSpeed, type, damage, knockBack, player.whoAmI); diff --git a/Items/Weapons/Melee/Violence.cs b/Items/Weapons/Melee/Violence.cs index 9e022355b3..4e2c3c558a 100644 --- a/Items/Weapons/Melee/Violence.cs +++ b/Items/Weapons/Melee/Violence.cs @@ -12,7 +12,7 @@ namespace CalamityMod.Items.Weapons.Melee public override void SetStaticDefaults() { DisplayName.SetDefault("Violence"); - Tooltip.SetDefault("Does things"); + Tooltip.SetDefault("Releases a blazing fork which stays near the mouse and shreds enemies"); } public override void SetDefaults() @@ -37,17 +37,12 @@ namespace CalamityMod.Items.Weapons.Melee item.shootSpeed = 15f; } - public override bool AltFunctionUse(Player player) => true; - public override bool CanUseItem(Player player) => player.altFunctionUse == 2 || player.ownedProjectileCounts[item.shoot] <= 0; public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) { - if (player.altFunctionUse != 2) - return true; - Vector2 shootVelocity = new Vector2(speedX, speedY); - Projectile.NewProjectile(position, shootVelocity, ModContent.ProjectileType(), damage, knockBack, player.whoAmI, 0f, shootVelocity.ToRotation()); + Projectile.NewProjectile(position, shootVelocity, type, damage, knockBack, player.whoAmI, 0f, shootVelocity.ToRotation()); return false; } } diff --git a/Projectiles/Magic/ApotheosisWorm.cs b/Projectiles/Magic/ApotheosisWorm.cs index 6d9f798e74..e466ab8f1a 100644 --- a/Projectiles/Magic/ApotheosisWorm.cs +++ b/Projectiles/Magic/ApotheosisWorm.cs @@ -210,7 +210,7 @@ namespace CalamityMod.Projectiles.Magic FlyAcceleration = MathHelper.Lerp(FlyAcceleration, idealFlyAcceleration, 0.3f); - float directionToTargetOrthogonality = Vector2.Dot(projectile.velocity.SafeNormalize(Vector2.Zero), projectile.DirectionTo(destination)); + float directionToTargetOrthogonality = Vector2.Dot(projectile.velocity.SafeNormalize(Vector2.Zero), projectile.SafeDirectionTo(destination)); // Fly towards the target if it's far. if (distanceFromDestination > 320f) diff --git a/Projectiles/Magic/FabRay.cs b/Projectiles/Magic/FabRay.cs index 2d75e9d2d7..137015fad6 100644 --- a/Projectiles/Magic/FabRay.cs +++ b/Projectiles/Magic/FabRay.cs @@ -45,7 +45,7 @@ namespace CalamityMod.Projectiles.Magic NPC potentialTarget = projectile.Center.ClosestNPCAt(180f, false); if (potentialTarget != null) { - Vector2 shootVelocity = projectile.DirectionTo(potentialTarget.Center) * 13f; + Vector2 shootVelocity = projectile.SafeDirectionTo(potentialTarget.Center) * 13f; Projectile.NewProjectile(projectile.Center - shootVelocity * 2.5f, shootVelocity, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); } diff --git a/Projectiles/Magic/RainbowRocket.cs b/Projectiles/Magic/RainbowRocket.cs index c5c12a0efa..6b2b51ff60 100644 --- a/Projectiles/Magic/RainbowRocket.cs +++ b/Projectiles/Magic/RainbowRocket.cs @@ -86,7 +86,7 @@ namespace CalamityMod.Projectiles.Magic projectile.velocity = projectile.velocity.RotatedBy(MathHelper.Clamp(angleOffset, -0.2f, 0.2f)); projectile.velocity = projectile.velocity.SafeNormalize(-Vector2.UnitY) * (projectile.velocity.Length() + HomingAcceleration); - if (Vector2.Dot(projectile.velocity.SafeNormalize(Vector2.Zero), projectile.DirectionTo(target.Center)) < 0.75f) + if (Vector2.Dot(projectile.velocity.SafeNormalize(Vector2.Zero), projectile.SafeDirectionTo(target.Center)) < 0.75f) projectile.velocity *= 0.75f; } #endregion diff --git a/Projectiles/Magic/RedirectingFire.cs b/Projectiles/Magic/RedirectingFire.cs index 808b34a254..d738f7a43a 100644 --- a/Projectiles/Magic/RedirectingFire.cs +++ b/Projectiles/Magic/RedirectingFire.cs @@ -46,7 +46,7 @@ namespace CalamityMod.Projectiles.Magic float delayFactor = Utils.InverseLerp(20f, 35f, Time, true); float homeSpeed = MathHelper.Lerp(0f, 0.075f, delayFactor); - projectile.velocity = Vector2.Lerp(projectile.velocity, projectile.DirectionTo(target.Center) * 16f, homeSpeed); + projectile.velocity = Vector2.Lerp(projectile.velocity, projectile.SafeDirectionTo(target.Center) * 16f, homeSpeed); projectile.velocity = projectile.velocity.SafeNormalize(Vector2.UnitY) * oldSpeed; projectile.position += (target.Center - projectile.Center).SafeNormalize(Vector2.Zero) * MathHelper.Lerp(25f, 1f, Utils.InverseLerp(100f, 360f, projectile.Distance(target.Center), true)) * delayFactor; } diff --git a/Projectiles/Melee/ViolenceSlashProjectile.cs b/Projectiles/Melee/ViolenceSlashProjectile.cs index dcc4ee91ba..90f645103c 100644 --- a/Projectiles/Melee/ViolenceSlashProjectile.cs +++ b/Projectiles/Melee/ViolenceSlashProjectile.cs @@ -65,7 +65,7 @@ namespace CalamityMod.Projectiles.Melee if (Main.myPlayer == projectile.owner && !projectile.WithinRange(Main.MouseWorld, projectile.height + 15f)) { - projectile.velocity = projectile.DirectionTo(Main.MouseWorld); + projectile.velocity = projectile.SafeDirectionTo(Main.MouseWorld); projectile.netSpam = 0; projectile.netUpdate = true; } diff --git a/Projectiles/Melee/ViolenceThrownProjectile.cs b/Projectiles/Melee/ViolenceThrownProjectile.cs index b9c33c3445..0fcf8ac827 100644 --- a/Projectiles/Melee/ViolenceThrownProjectile.cs +++ b/Projectiles/Melee/ViolenceThrownProjectile.cs @@ -50,7 +50,7 @@ namespace CalamityMod.Projectiles.Melee { ReturnToOwner(); - float idealAngle = projectile.AngleTo(Owner.Center) - MathHelper.PiOver4 + MathHelper.Pi; + float idealAngle = projectile.AngleTo(Owner.Center) - MathHelper.PiOver4; projectile.rotation = projectile.rotation.AngleLerp(idealAngle, 0.1f); projectile.rotation = projectile.rotation.AngleTowards(idealAngle, 0.25f); } @@ -69,7 +69,7 @@ namespace CalamityMod.Projectiles.Melee if (projectile.WithinRange(Main.MouseWorld, projectile.velocity.Length() * 0.7f)) projectile.Center = Main.MouseWorld; else - projectile.velocity = (projectile.velocity * 6f + projectile.DirectionTo(Main.MouseWorld) * 14f) / 7f; + projectile.velocity = (projectile.velocity * 3f + projectile.DirectionTo(Main.MouseWorld) * 19f) / 4f; projectile.netSpam = 0; projectile.netUpdate = true; } @@ -77,7 +77,7 @@ namespace CalamityMod.Projectiles.Melee internal void ReturnToOwner() { projectile.Center = Vector2.Lerp(projectile.Center, Owner.Center, 0.02f); - projectile.velocity = projectile.DirectionTo(Owner.Center) * 15f; + projectile.velocity = projectile.SafeDirectionTo(Owner.Center) * 22f; if (projectile.Hitbox.Intersects(Owner.Hitbox)) { for (int i = 0; i < 75; i++) diff --git a/Projectiles/Ranged/CondemnationArrowHoming.cs b/Projectiles/Ranged/CondemnationArrowHoming.cs index 6e5d09f1d1..14d7acf2b3 100644 --- a/Projectiles/Ranged/CondemnationArrowHoming.cs +++ b/Projectiles/Ranged/CondemnationArrowHoming.cs @@ -39,7 +39,7 @@ namespace CalamityMod.Projectiles.Ranged NPC potentialTarget = projectile.Center.ClosestNPCAt(1500f, false); if (potentialTarget != null) - projectile.velocity = (projectile.velocity * 29f + projectile.DirectionTo(potentialTarget.Center) * 21f) / 30f; + projectile.velocity = (projectile.velocity * 29f + projectile.SafeDirectionTo(potentialTarget.Center) * 21f) / 30f; projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2; Time++; } diff --git a/Projectiles/Ranged/PrismComet.cs b/Projectiles/Ranged/PrismComet.cs index 044092df73..5fc4a36842 100644 --- a/Projectiles/Ranged/PrismComet.cs +++ b/Projectiles/Ranged/PrismComet.cs @@ -48,7 +48,7 @@ namespace CalamityMod.Projectiles.Ranged { NPC potentialTarget = projectile.Center.ClosestNPCAt(1050f); if (potentialTarget != null) - projectile.velocity = (projectile.velocity * 12f + projectile.DirectionTo(potentialTarget.Center) * 19f) / 13f; + projectile.velocity = (projectile.velocity * 12f + projectile.SafeDirectionTo(potentialTarget.Center) * 19f) / 13f; } else projectile.velocity *= 1.05f; diff --git a/Projectiles/Ranged/PrismMine.cs b/Projectiles/Ranged/PrismMine.cs index 9cf3e0b32f..b2e06f1ef6 100644 --- a/Projectiles/Ranged/PrismMine.cs +++ b/Projectiles/Ranged/PrismMine.cs @@ -83,7 +83,7 @@ namespace CalamityMod.Projectiles.Ranged Vector2 laserOrigin = frame.Size() * 0.5f; while (remainingDistance > frame.Height * laserScale) { - Vector2 laserDrawPosition = projectile.Center + projectile.DirectionTo(destination) * remainingDistance - Main.screenPosition; + Vector2 laserDrawPosition = projectile.Center + projectile.SafeDirectionTo(destination, -Vector2.UnitY) * remainingDistance - Main.screenPosition; spriteBatch.Draw(laserTexture, laserDrawPosition, frame, laserColor, rotation, laserOrigin, laserScale, SpriteEffects.None, 0f); remainingDistance -= frame.Height * laserScale; } diff --git a/Projectiles/Rogue/PrismRocket.cs b/Projectiles/Rogue/PrismRocket.cs index 90d8e9004e..482518b704 100644 --- a/Projectiles/Rogue/PrismRocket.cs +++ b/Projectiles/Rogue/PrismRocket.cs @@ -49,7 +49,7 @@ namespace CalamityMod.Projectiles.Rogue if (!projectile.WithinRange(target.Center, 30f)) { - projectile.velocity = (projectile.velocity * 5f + projectile.DirectionTo(target.Center) * newSpeed) / 6f; + projectile.velocity = (projectile.velocity * 5f + projectile.SafeDirectionTo(target.Center) * newSpeed) / 6f; projectile.velocity = projectile.velocity.ToRotation().AngleTowards(projectile.AngleTo(target.Center), 0.15f).ToRotationVector2() * newSpeed; } } diff --git a/Projectiles/Rogue/SacrificeProjectile.cs b/Projectiles/Rogue/SacrificeProjectile.cs index 1487b2ab70..e86e784981 100644 --- a/Projectiles/Rogue/SacrificeProjectile.cs +++ b/Projectiles/Rogue/SacrificeProjectile.cs @@ -43,7 +43,7 @@ namespace CalamityMod.Projectiles.Rogue if (ReturningToOwner) { projectile.timeLeft = 2; - projectile.velocity = projectile.DirectionTo(Owner.Center) * 24f; + projectile.velocity = projectile.SafeDirectionTo(Owner.Center) * 24f; projectile.rotation = projectile.velocity.ToRotation() + MathHelper.Pi + MathHelper.PiOver4; // Heal the player and disappear when touching them. diff --git a/Projectiles/Summon/DaedalusGolem.cs b/Projectiles/Summon/DaedalusGolem.cs index 0090806db9..ef481613a1 100644 --- a/Projectiles/Summon/DaedalusGolem.cs +++ b/Projectiles/Summon/DaedalusGolem.cs @@ -138,7 +138,7 @@ namespace CalamityMod.Projectiles.Summon Main.PlaySound(SoundID.Item122, ArmPosition); if (Main.myPlayer == projectile.owner) { - Vector2 initialVelocity = projectile.DirectionTo(potentialTarget.Center) * 2f; + Vector2 initialVelocity = projectile.SafeDirectionTo(potentialTarget.Center) * 2f; if (Main.rand.NextBool(2)) initialVelocity = initialVelocity.RotatedByRandom(0.4f); float initialAngle = initialVelocity.ToRotation(); @@ -148,7 +148,7 @@ namespace CalamityMod.Projectiles.Summon } else if (!UsingChargedLaserAttack && AttackTimer == ChargedPelletAttackTime / 2 && Main.myPlayer == projectile.owner) { - Vector2 initialVelocity = projectile.DirectionTo(potentialTarget.Center + potentialTarget.velocity * 15f) * 19f; + Vector2 initialVelocity = projectile.SafeDirectionTo(potentialTarget.Center + potentialTarget.velocity * 15f) * 19f; Projectile.NewProjectile(ArmPosition, initialVelocity, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); } } @@ -187,7 +187,7 @@ namespace CalamityMod.Projectiles.Summon projectile.tileCollide = false; if (projectile.DistanceSQ(destination - Vector2.UnitY * 16f) > 10f * 10f) - projectile.velocity = projectile.DirectionTo(destination - Vector2.UnitY * 16f) * 6f; + projectile.velocity = projectile.SafeDirectionTo(destination - Vector2.UnitY * 16f) * 6f; else StuckWalkThroughWallsTimer = 0; diff --git a/Projectiles/Summon/EyeOfNightSummon.cs b/Projectiles/Summon/EyeOfNightSummon.cs index a9b64e428c..6af7ff3d56 100644 --- a/Projectiles/Summon/EyeOfNightSummon.cs +++ b/Projectiles/Summon/EyeOfNightSummon.cs @@ -89,7 +89,7 @@ namespace CalamityMod.Projectiles.Summon internal void FlyNearOwner() { Vector2 destination = Owner.Top - Vector2.UnitY * 45f + (projectile.identity * 0.9f).ToRotationVector2() * 16f; - Vector2 idealVelocity = projectile.DirectionTo(destination) * MathHelper.Lerp(2.3f, 8f, Utils.InverseLerp(16f, 160f, projectile.Distance(destination))); + Vector2 idealVelocity = projectile.SafeDirectionTo(destination) * MathHelper.Lerp(2.3f, 8f, Utils.InverseLerp(16f, 160f, projectile.Distance(destination))); if (projectile.velocity.Length() < 0.4f) projectile.velocity = Vector2.UnitY.RotatedBy(Main.rand.NextFloat(0.5f, 1.1f) * Main.rand.NextBool(2).ToDirectionInt()) * -3.6f; else if (!projectile.WithinRange(destination, 20f)) @@ -110,7 +110,7 @@ namespace CalamityMod.Projectiles.Summon { if (Main.myPlayer == projectile.owner && HoverTime % 30 == 29) { - Projectile.NewProjectile(projectile.Center, projectile.DirectionTo(target.Center) * 8f, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); + Projectile.NewProjectile(projectile.Center, projectile.SafeDirectionTo(target.Center) * 8f, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); HoverTime++; } diff --git a/Projectiles/Summon/FleshBallMinion.cs b/Projectiles/Summon/FleshBallMinion.cs index 210163db55..57dab5bbee 100644 --- a/Projectiles/Summon/FleshBallMinion.cs +++ b/Projectiles/Summon/FleshBallMinion.cs @@ -125,7 +125,7 @@ namespace CalamityMod.Projectiles.Summon if (SittingOnGround && HopTimer % 20f == 19f) { - projectile.velocity = projectile.DirectionTo(target.Center) * 6f + new Vector2(Math.Sign(projectile.velocity.X) * 2f, -7f); + projectile.velocity = projectile.SafeDirectionTo(target.Center) * 6f + new Vector2(Math.Sign(projectile.velocity.X) * 2f, -7f); // Release a bunch of blood. if (Main.myPlayer == projectile.owner) diff --git a/Projectiles/Summon/FlowersOfMortalityPetal.cs b/Projectiles/Summon/FlowersOfMortalityPetal.cs index 17244ae025..b743c1018e 100644 --- a/Projectiles/Summon/FlowersOfMortalityPetal.cs +++ b/Projectiles/Summon/FlowersOfMortalityPetal.cs @@ -58,7 +58,7 @@ namespace CalamityMod.Projectiles.Summon NPC potentialTarget = projectile.Center.MinionHoming(1050f, Owner, false); if (Time % 25 == 24 && Main.myPlayer == projectile.owner && potentialTarget != null) { - Vector2 shootVelocity = projectile.DirectionTo(potentialTarget.Center) * 10f; + Vector2 shootVelocity = projectile.SafeDirectionTo(potentialTarget.Center) * 10f; Projectile.NewProjectile(projectile.Center, shootVelocity, ModContent.ProjectileType(), projectile.damage / 3, projectile.knockBack, projectile.owner); } projectile.Center = player.Center + OffsetAngle.ToRotationVector2() * (150f + (float)Math.Sin(Time * 0.08f) * 15f); diff --git a/Projectiles/Summon/LostSoulGiant.cs b/Projectiles/Summon/LostSoulGiant.cs index 13123a056d..b7caaff612 100644 --- a/Projectiles/Summon/LostSoulGiant.cs +++ b/Projectiles/Summon/LostSoulGiant.cs @@ -56,7 +56,7 @@ namespace CalamityMod.Projectiles.Summon public static void HomeInOnTarget(Projectile projectile, NPC target) { float speed = MathHelper.Lerp(11f, 21f, (float)Math.Sin(projectile.identity % 7f / 7f * MathHelper.TwoPi) * 0.5f + 0.5f); - projectile.velocity = Vector2.Lerp(projectile.velocity, projectile.DirectionTo(target.Center) * speed, 0.075f); + projectile.velocity = Vector2.Lerp(projectile.velocity, projectile.SafeDirectionTo(target.Center) * speed, 0.075f); } public override Color? GetAlpha(Color lightColor) diff --git a/Projectiles/Summon/MortalityBeam.cs b/Projectiles/Summon/MortalityBeam.cs index 3faca61c1d..622f0b5b14 100644 --- a/Projectiles/Summon/MortalityBeam.cs +++ b/Projectiles/Summon/MortalityBeam.cs @@ -52,7 +52,7 @@ namespace CalamityMod.Projectiles.Summon Time++; NPC potentialTarget = projectile.Center.MinionHoming(1000f, Main.player[projectile.owner], false); if (potentialTarget != null) - projectile.velocity = (projectile.velocity * 5f + projectile.DirectionTo(potentialTarget.Center) * 13f) / 6f; + projectile.velocity = (projectile.velocity * 5f + projectile.SafeDirectionTo(potentialTarget.Center) * 13f) / 6f; } public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) diff --git a/Projectiles/Summon/SeekerSummonProj.cs b/Projectiles/Summon/SeekerSummonProj.cs index cbf10e1020..7805fd543a 100644 --- a/Projectiles/Summon/SeekerSummonProj.cs +++ b/Projectiles/Summon/SeekerSummonProj.cs @@ -103,7 +103,7 @@ namespace CalamityMod.Projectiles.Summon projectile.Center = Vector2.Lerp(projectile.Center, destination, 0.03f); if (!projectile.WithinRange(destination, 20f)) - projectile.velocity = (projectile.velocity * 20f + projectile.DirectionTo(destination) * 16f) / 21f; + projectile.velocity = (projectile.velocity * 20f + projectile.SafeDirectionTo(destination) * 16f) / 21f; if (!projectile.WithinRange(Owner.Center, 1800f)) { @@ -142,9 +142,9 @@ namespace CalamityMod.Projectiles.Summon projectile.spriteDirection = (projectile.velocity.X > 0f).ToDirectionInt(); if (!projectile.WithinRange(target.Center, 400f)) - projectile.velocity = (projectile.velocity * 10f + projectile.DirectionTo(target.Center) * 22f) / 11f; + projectile.velocity = (projectile.velocity * 10f + projectile.SafeDirectionTo(target.Center) * 22f) / 11f; else if (projectile.velocity.Length() < 28f) - projectile.velocity = projectile.DirectionTo(target.Center) * 29f; + projectile.velocity = projectile.SafeDirectionTo(target.Center) * 29f; } } } diff --git a/Projectiles/Summon/SlimePuppet.cs b/Projectiles/Summon/SlimePuppet.cs index a7b390487e..2141fdc467 100644 --- a/Projectiles/Summon/SlimePuppet.cs +++ b/Projectiles/Summon/SlimePuppet.cs @@ -48,14 +48,14 @@ namespace CalamityMod.Projectiles.Summon Vector2 destination = Owner.Center - Vector2.UnitY.RotatedBy(destinationAngularOffset) * 160f; if (projectile.DistanceSQ(destination) > 18f * 18f) - projectile.velocity = (projectile.velocity * 20f + projectile.DirectionTo(destination) * 9f) / 21f; + projectile.velocity = (projectile.velocity * 20f + projectile.SafeDirectionTo(destination) * 9f) / 21f; } else { float nudgedVelocityDirection = projectile.velocity.ToRotation().AngleTowards(projectile.AngleTo(potentialTarget.Center), 0.078f); projectile.velocity = nudgedVelocityDirection.ToRotationVector2() * MathHelper.Lerp(projectile.velocity.Length(), 16f, 0.25f); - if (projectile.DistanceSQ(potentialTarget.Center) < 120f * 120f) - projectile.Center += projectile.DirectionTo(potentialTarget.Center) * 3f; + if (projectile.WithinRange(potentialTarget.Center, 120f)) + projectile.Center += projectile.SafeDirectionTo(potentialTarget.Center) * 3f; } if (projectile.ai[0] > 0f) { diff --git a/Projectiles/Summon/ViridVanguardBlade.cs b/Projectiles/Summon/ViridVanguardBlade.cs index c6586277c0..df19971af4 100644 --- a/Projectiles/Summon/ViridVanguardBlade.cs +++ b/Projectiles/Summon/ViridVanguardBlade.cs @@ -121,7 +121,7 @@ namespace CalamityMod.Projectiles.Summon else if (FiringTime == 80f) { PostSliceDeathTimer = 80; - projectile.velocity = projectile.DirectionTo(Main.MouseWorld) * 30f; + projectile.velocity = projectile.SafeDirectionTo(Main.MouseWorld) * 30f; } else if (FiringTime == 1f) { diff --git a/Projectiles/Summon/WitherBlossom.cs b/Projectiles/Summon/WitherBlossom.cs index 003223e8b8..94bf3ee576 100644 --- a/Projectiles/Summon/WitherBlossom.cs +++ b/Projectiles/Summon/WitherBlossom.cs @@ -51,7 +51,7 @@ namespace CalamityMod.Projectiles.Summon NPC potentialTarget = projectile.Center.MinionHoming(950f, Owner); if (Time % 50 == 49 && Main.myPlayer == projectile.owner && potentialTarget != null) { - Vector2 shootVelocity = projectile.DirectionTo(potentialTarget.Center).RotatedByRandom(0.25f) * 8f; + Vector2 shootVelocity = projectile.SafeDirectionTo(potentialTarget.Center).RotatedByRandom(0.25f) * 8f; Projectile.NewProjectile(projectile.Center, shootVelocity, ModContent.ProjectileType(), projectile.damage, projectile.knockBack, projectile.owner); } projectile.Center = player.Center + OffsetAngle.ToRotationVector2() * 150f; diff --git a/Projectiles/Summon/WitherBolt.cs b/Projectiles/Summon/WitherBolt.cs index 34abcec8de..fed98e329a 100644 --- a/Projectiles/Summon/WitherBolt.cs +++ b/Projectiles/Summon/WitherBolt.cs @@ -39,7 +39,7 @@ namespace CalamityMod.Projectiles.Summon NPC potentialTarget = projectile.Center.MinionHoming(800f, Main.player[projectile.owner]); if (potentialTarget != null) - projectile.velocity = (projectile.velocity * 3f + projectile.DirectionTo(potentialTarget.Center) * oldSpeed) / 4f; + projectile.velocity = (projectile.velocity * 3f + projectile.SafeDirectionTo(potentialTarget.Center) * oldSpeed) / 4f; projectile.velocity = projectile.velocity.SafeNormalize(Vector2.UnitY) * oldSpeed * 1.01f; projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2;