Microsoft.Xna.Framework.Vector2.Normalize C# (CSharp) Method

Normalize() public method

Turns the current vector into a unit vector. The result is a vector one unit in length pointing in the same direction as the original vector.
public Normalize ( ) : void
return void
        public void Normalize()
        {
            float num = this.X * this.X + this.Y * this.Y;
            float num2 = 1f / (float)Math.Sqrt((double)num);
            this.X *= num2;
            this.Y *= num2;
        }
        /// <summary>Creates a unit vector from the specified vector. The result is a vector one unit in length pointing in the same direction as the original vector.</summary>

Same methods

Vector2::Normalize ( Vector2 value ) : Vector2
Vector2::Normalize ( Vector2 &value, Vector2 &result ) : void

Usage Example

コード例 #1
1
 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 direction = new Vector2(speedX, speedY);
     direction.Normalize();
     position += direction * item.width;
     return true;
 }
All Usage Examples Of Microsoft.Xna.Framework.Vector2::Normalize