Terraria.Player.RotatedRelativePoint C# (CSharp) Method

RotatedRelativePoint() public method

public RotatedRelativePoint ( Vector2 pos, bool rotateForward = true ) : Vector2
pos Vector2
rotateForward bool
return Vector2
        public Vector2 RotatedRelativePoint(Vector2 pos, bool rotateForward = true)
        {
            Vector2 vector2 = this.position + this.fullRotationOrigin;
            Matrix rotationZ = Matrix.CreateRotationZ(this.fullRotation * (float)Utils.ToInt(rotateForward));
            pos -= this.position + this.fullRotationOrigin;
            pos = Vector2.Transform(pos, rotationZ);
            return pos + vector2;
        }

Usage Example

Example #1
0
        public override bool Shoot(Player player, ref Microsoft.Xna.Framework.Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            Vector2 relativeCenter = player.RotatedRelativePoint(player.MountedCenter, true);

            float num5 = player.inventory[player.selectedItem].shootSpeed * item.scale;
            Vector2 vector2_3 = Main.screenPosition + new Vector2((float)Main.mouseX, (float)Main.mouseY) - relativeCenter;
            if ((double)player.gravDir == -1.0)
                vector2_3.Y = (float)(Main.screenHeight - Main.mouseY) + Main.screenPosition.Y - relativeCenter.Y;
            Vector2 vector2_4 = Vector2.Normalize(vector2_3);
            if (float.IsNaN(vector2_4.X) || float.IsNaN(vector2_4.Y))
                vector2_4 = -Vector2.UnitY;
            vector2_4 *= num5;
            item.velocity = vector2_4;

            float rotationOffset = 8;
            Vector2 projectilePos = player.Center;
            Vector2 spinningpoint = Vector2.Normalize(item.velocity) * rotationOffset;
            for (int i = 0; i < 2; ++i)
            {
                spinningpoint = Utils.RotatedBy(spinningpoint, Main.rand.NextDouble() * 0.25F, new Vector2());
                if (float.IsNaN(spinningpoint.X) || float.IsNaN(spinningpoint.Y))
                    spinningpoint = -Vector2.UnitY;

                float angle = (float)Math.Atan(speedY / speedX);
                Vector2 vector2 = new Vector2(projectilePos.X + 30 * (float)Math.Cos(angle), projectilePos.Y + 30 * (float)Math.Sin(angle));
                float mouseX = Main.mouseX + Main.screenPosition.X;
                if (mouseX < projectilePos.X)
                {
                    vector2 = new Vector2(projectilePos.X - 30 * (float)Math.Cos(angle), projectilePos.Y - 30 * (float)Math.Sin(angle));
                }

                Projectile.NewProjectile(vector2.X, vector2.Y, spinningpoint.X, spinningpoint.Y, type, damage, knockBack, Main.myPlayer);
            }
            return false;
        }
All Usage Examples Of Terraria.Player::RotatedRelativePoint
Player