public void RotateAim(Aim aim, Player.Side side) { float rightThumbstickY = currentGamePadState.ThumbSticks.Right.Y; float rightThumbstickX = currentGamePadState.ThumbSticks.Right.X; if ((rightThumbstickX != 0 || rightThumbstickY != 0)) { float thumbstickAngle = 0; float thumbstickAngleAngleInDegrees = 0; thumbstickAngle = (float)Math.Atan2(rightThumbstickY, rightThumbstickX); thumbstickAngleAngleInDegrees = (float)aim.RadianToDegree(thumbstickAngle); if (side == Player.Side.Left) { if (thumbstickAngleAngleInDegrees >= 0) { thumbstickAngleAngleInDegrees = 90 - (thumbstickAngleAngleInDegrees - 90); } else { thumbstickAngleAngleInDegrees = -90 + ((thumbstickAngleAngleInDegrees + 90) * -1); } } aim.Rotate(thumbstickAngleAngleInDegrees); } aim.angle = aim.DegreeToRadian(aim.angleInDegrees); }
public void SetDefaultAim(Aim aim) { float leftThumbstickY = currentGamePadState.ThumbSticks.Left.Y; float leftThumbstickX = currentGamePadState.ThumbSticks.Left.X; if ((leftThumbstickX != 0 || leftThumbstickY != 0)) { float thumbstickAngle = 0; float thumbstickAngleAngleInDegrees = 0; thumbstickAngle = (float)Math.Atan2(leftThumbstickY, leftThumbstickX); thumbstickAngleAngleInDegrees = (float)aim.RadianToDegree(thumbstickAngle); if (thumbstickAngleAngleInDegrees > 22.5 && thumbstickAngleAngleInDegrees <= 67.5) { aim.angleInDegrees = 45; } else if (thumbstickAngleAngleInDegrees > 67.5 && thumbstickAngleAngleInDegrees <= 112.5) { aim.angleInDegrees = 90; } else if (thumbstickAngleAngleInDegrees > 112.5 && thumbstickAngleAngleInDegrees <= 157.5) { aim.angleInDegrees = 45; } else if ((thumbstickAngleAngleInDegrees > 157.5 && thumbstickAngleAngleInDegrees <= 180) || (thumbstickAngleAngleInDegrees >= -180 && thumbstickAngleAngleInDegrees <= -157.5)) { aim.angleInDegrees = 0; } else if (thumbstickAngleAngleInDegrees > -157.5 && thumbstickAngleAngleInDegrees <= -112.5) { aim.angleInDegrees = -45; } else if (thumbstickAngleAngleInDegrees > -112.5 && thumbstickAngleAngleInDegrees <= -67.5) { aim.angleInDegrees = -90; } else if (thumbstickAngleAngleInDegrees > -67.5 && thumbstickAngleAngleInDegrees <= -22.5) { aim.angleInDegrees = -45; } else if ((thumbstickAngleAngleInDegrees > -22.5 && thumbstickAngleAngleInDegrees <= 0) || (thumbstickAngleAngleInDegrees >= 0 && thumbstickAngleAngleInDegrees <= 22.5)) { aim.angleInDegrees = 0; } } else { aim.angleInDegrees = 0; } }