//Gets us the rotation from the stick: (taking this from memory, som might be reverse order etc)
float radians = Math.Atan2(GamePadState.ThumbSticks.Left.Y, GamePadState.ThumbSticks.Left.X);
//Top half: 0 = stick to the right to Pi = stick to the left.
//Bottom half: 0 = stick to the right to -Pi = stick to the left.
//I'll just do this for 4 directions, as I have limited time, and the concept should be obvious:
if ((radians > Math.Pi * -0.25f) && (radians < Math.Pi * 0.25f))
//Direction is Right
else if ((radians >= Math.Pi * 0.25f) && (radians < Math.Pi * 0.75f))
//Direction is Up
else if ((radians >= Math.Pi * 0.75f) || (radians <= Math.Pi * -0.75f))
//Direction is Left
else if ((radians <= Math.Pi * -0.25f) && (radians > Math.Pi * -0.75f))
//Direction is Down
より多くの角度を取得するには、これをさらに行うだけです。サムスティックを使用する方が簡単な場合があります。
Vector2 stick = GamePadState.ThumbSticks.Left;
stick.Normalize();
if (stick.X >= 0.5f) (NE, E, SE)
{
if (stick.Y >= 0.5f)
//Direction is NE
else if (stick.Y <= -0.5f)
//Direction is SE
else
//Direction is E
}
else if (stick.X <= -0.5f) (NW, W, SW)
{
if (stick.Y >= 0.5f)
//Direction is NW
else if (stick.Y <= -0.5f)
//Direction is SW
else
//Direction is W
}
else if (stick.Y >= 0.5f)
//Direction is N
else if (stick.Y <= -0.5f)
//Direction is S
else
//Direction is nothing. should not happen
編集; サムスティックの方向に弾丸を発射するには、サムスティックの正規化された * 速度を弾丸の速度として使用します。