public Vector2 GetStickDirection(XInput.Stick stick) { if (stick == XInput.Stick.Left) { return(new Vector2(state.ThumbSticks.Left.X, state.ThumbSticks.Left.Y)); } else if (stick == XInput.Stick.Right) { return(new Vector2(state.ThumbSticks.Right.X, state.ThumbSticks.Right.Y)); } return(Vector2.zero); }
public XInput.Direction StickDirectionChanged(XInput.Stick stick) { if (StickInDeadZone(prevState, stick) && !StickInDeadZone(state, stick)) { float deltaX = 0, deltaY = 0; if (stick == XInput.Stick.Left) { deltaX = state.ThumbSticks.Left.X - prevState.ThumbSticks.Left.X; deltaY = state.ThumbSticks.Left.Y - prevState.ThumbSticks.Left.Y; } else if (stick == XInput.Stick.Right) { deltaX = state.ThumbSticks.Right.X - prevState.ThumbSticks.Right.X; deltaY = state.ThumbSticks.Right.Y - prevState.ThumbSticks.Right.Y; } if (Mathf.Abs(deltaX) < detectDirectionThreshold && Mathf.Abs(deltaY) > detectDirectionThreshold) // Vertical { return(deltaY > 0 ? XInput.Direction.Up : XInput.Direction.Down); } else if (Mathf.Abs(deltaX) > detectDirectionThreshold && Mathf.Abs(deltaY) < detectDirectionThreshold) // Horizontal { return(deltaX > 0 ? XInput.Direction.Right : XInput.Direction.Left); } else if (deltaX > detectDirectionThreshold) { if (deltaY > detectDirectionThreshold) { return(XInput.Direction.UpRight); } else if (deltaY < detectDirectionThreshold) { return(XInput.Direction.DownRight); } } else if (deltaX < detectDirectionThreshold) { if (deltaY > detectDirectionThreshold) { return(XInput.Direction.UpLeft); } else if (deltaY < detectDirectionThreshold) { return(XInput.Direction.DownLeft); } } } return(XInput.Direction.None); }
private bool StickInDeadZone(GamePadState state, XInput.Stick stick) { Vector2 stickDir = Vector2.zero; if (stick == XInput.Stick.Left) { stickDir = new Vector2(state.ThumbSticks.Left.X, state.ThumbSticks.Left.Y); } else if (stick == XInput.Stick.Right) { stickDir = new Vector2(state.ThumbSticks.Right.X, state.ThumbSticks.Right.Y); } return(stickDir.magnitude < deadzoneRadius); }
public bool StickInDeadZone(XInput.Stick stick) { return(StickInDeadZone(state, stick)); }
public bool StickReleased(XInput.Stick stick) { return(!StickInDeadZone(prevState, stick) && StickInDeadZone(state, stick)); }