Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ AI_159_PaperAirplanes()

void Terraria.Projectile.AI_159_PaperAirplanes ( )
inlineprivate

Definition at line 40013 of file Projectile.cs.

40014 {
40015 if (ai[1] == 0f)
40016 {
40017 direction = ((velocity.X > 0f) ? 1 : (-1));
40018 rotation = velocity.ToRotation();
40019 ai[1] = 1f;
40020 ai[0] = -Main.rand.Next(30, 80);
40021 netUpdate = true;
40022 }
40023 if (wet && owner == Main.myPlayer)
40024 {
40025 Kill();
40026 }
40027 ai[0] += 1f;
40028 Vector2 vector = rotation.ToRotationVector2() * 8f;
40029 float y = (float)Math.Sin((float)Math.PI * 2f * (float)(Main.timeForVisualEffects % 90.0 / 90.0)) * (float)direction * Main.WindForVisuals;
40030 Vector2 v = vector + new Vector2(Main.WindForVisuals, y);
40031 _ = Vector2.UnitX * direction;
40032 bool flag = direction == Math.Sign(Main.WindForVisuals) && velocity.Length() > 3f;
40033 bool num = ai[0] >= 20f && ai[0] <= 69f;
40034 if (ai[0] == 70f)
40035 {
40036 ai[0] = -Main.rand.Next(120, 600);
40037 }
40038 bool num2 = num && flag;
40039 if (num2)
40040 {
40041 float lerpValue = Utils.GetLerpValue(0f, 30f, ai[0], clamped: true);
40042 v = vector.RotatedBy((float)(-direction) * ((float)Math.PI * 2f) * 0.02f * lerpValue);
40043 }
40044 velocity = v.SafeNormalize(Vector2.UnitY) * velocity.Length();
40045 if (!num2)
40046 {
40047 float num3 = MathHelper.Lerp(0.15f, 0.05f, Math.Abs(Main.WindForVisuals));
40048 if (timeLeft % 40 < 20)
40049 {
40050 velocity.Y -= num3;
40051 }
40052 else
40053 {
40054 velocity.Y += num3;
40055 }
40056 if (velocity.Y < -2f)
40057 {
40058 velocity.Y = -2f;
40059 }
40060 if (velocity.Y > 2f)
40061 {
40062 velocity.Y = 2f;
40063 }
40064 velocity.X = MathHelper.Clamp(velocity.X + Main.WindForVisuals * 0.006f, -6f, 6f);
40065 if (velocity.X * oldVelocity.X < 0f)
40066 {
40067 direction *= -1;
40068 ai[0] = -Main.rand.Next(120, 300);
40069 netUpdate = true;
40070 }
40071 }
40072 rotation = velocity.ToRotation();
40074 }
static float Lerp(float value1, float value2, float amount)
Definition MathHelper.cs:53
static float Clamp(float value, float min, float max)
Definition MathHelper.cs:46
static double Abs(double value)
static double Sin(double a)
const double PI
Definition Math.cs:16
static int Sign(decimal value)
Definition Math.cs:1202
Vector2 velocity
Definition Entity.cs:16
Vector2 oldVelocity
Definition Entity.cs:20

References System.Math.Abs(), Microsoft.Xna.Framework.MathHelper.Clamp(), Terraria.Utils.GetLerpValue(), Microsoft.Xna.Framework.MathHelper.Lerp(), Terraria.Main.myPlayer, Terraria.Main.rand, System.Math.Sign(), System.Math.Sin(), Terraria.Main.timeForVisualEffects, Microsoft.Xna.Framework.Vector2.UnitY, and Terraria.Main.WindForVisuals.