### Create a Basic Input Axis (Lua) Source: https://github.com/neond00m/axis/blob/main/docs/Introduction/getting_started.md This example demonstrates how to create a basic input axis in Lua. It defines an axis named 'attack' that listens for keyboard 'E', mouse button 1, and controller 'ButtonR2' inputs. ```lua local attack = Axis.input { Enum.KeyCode.E, -- for keyboard, though usually redundant with mouse Enum.UserInputType.MouseButton1, -- for mouse Enum.KeyCode.ButtonR2, -- for xbox/ps4 controllers } ``` -------------------------------- ### Create Input Axis with Custom Weights (Lua) Source: https://github.com/neond00m/axis/blob/main/docs/Introduction/getting_started.md This Lua example shows how to create an input axis with custom, non-standard weights. It assigns a weight of 3 to key 'Q' and 1 to key 'W', demonstrating how these weights affect the total input value. ```lua local acceleratePedal = Axis.input { [Enum.KeyCode.Q] = 3, [Enum.KeyCode.W] = 1, } local pedal = acceleratePedal:read() -- pedal will equal either 4, 3, 1, or 0 ``` -------------------------------- ### Define Input with Controller Support (Lua) Source: https://github.com/neond00m/axis/blob/main/docs/Devices/controller.md Defines an input action, such as jumping, and specifies which controller it should primarily be associated with. This example shows how to bind a keyboard key and a controller button to the same action, defaulting to controller 1. ```lua local jump = Axis.input { Enum.KeyCode.Space, -- any other inputs will be treated as controller 1 Enum.KeyCode.ButtonA, } ``` -------------------------------- ### Create Vector Axis with Mouse Sensitivity (Lua) Source: https://github.com/neond00m/axis/blob/main/docs/Introduction/getting_started.md This Lua example demonstrates creating a vector axis for mouse movement with a custom sensitivity weight. It assigns a weight of 50 to Enum.UserInputType.MouseMovement, effectively scaling the mouse's input. ```lua local mouse = Axis.input { [Enum.UserInputType.MouseMovement] = 50, -- [Enum.UserInputType.MouseMovement] = Vector2.new(0, 1), } local delta = mouse:read() -- mouse movement is a variable-magnitude vector, but we still multiply by 50 ``` -------------------------------- ### Create Mouse Wheel Input Axis (Lua) Source: https://github.com/neond00m/axis/blob/main/docs/Introduction/getting_started.md This Lua example creates an input axis specifically for the mouse wheel. The mouse wheel can return values of 0, 1 (up), or -1 (down), allowing for directional input. ```lua local zoom = Axis.input { Enum.UserInputType.MouseWheel } ``` -------------------------------- ### Install Axis via Pesde Source: https://context7.com/neond00m/axis/llms.txt Installs the Axis library using the pesde package manager. This is a quick way to add the library to your project. ```bash pesde add killergg/axis ``` -------------------------------- ### Define Jump Input Axis (Lua) Source: https://github.com/neond00m/axis/blob/main/docs/Introduction/example_game.md Defines a 'jump' input axis using a combination of keyboard and gamepad inputs. This allows the jump action to be triggered by the Space key or the 'A' button on a gamepad. This is a configuration for the Axis input system. ```lua jump = Axis.input { Enum.KeyCode.Space, Enum.KeyCode.ButtonA } ``` -------------------------------- ### Install Axis via Wally Source: https://context7.com/neond00m/axis/llms.txt Adds the Axis library as a dependency to your project's wally.toml file. Ensure you specify the correct version. ```toml # Add to your wally.toml axis = "neond00m/axis@0.2.4" ``` -------------------------------- ### Define Crouch Input - Luau Source: https://github.com/neond00m/axis/blob/main/docs/Introduction/example_game.md Defines the input mapping for the crouch action, including various keyboard keys and the right thumbstick for console input. This setup allows for flexible input handling across different devices. ```luau --inputMap.luau crouch = input { Enum.KeyCode.C, Enum.KeyCode.LeftControl, Enum.KeyCode.RightControl, Enum.KeyCode.ButtonR3, -- pressing on the right thumbstick will crouch! } ``` -------------------------------- ### Create Input Axis with Negative Weights (Lua) Source: https://github.com/neond00m/axis/blob/main/docs/Introduction/getting_started.md This Lua snippet illustrates creating an input axis with custom weights, including negative values. It shows how 'A' is assigned a weight of -1 and 'D' a default weight of 1, useful for bidirectional movement. ```lua local movementIn2D = Axis.input { [Enum.KeyCode.A] = -1, Enum.KeyCode.D, -- by default, given a weight of positive 1 -- [Enum.KeyCode.D] = 1, -- this is explicit, but has same behavior } ``` -------------------------------- ### Configure Camera Drag Input Axes (Lua) Source: https://github.com/neond00m/axis/blob/main/docs/Introduction/example_game.md Sets up input axes for camera movement, including a primary 'drag' axis for general movement and a 'dragHold' axis for locking the mouse. The 'drag' axis utilizes mouse movement and thumbstick input, with specific vector mappings for left and right inputs. Dependencies include an 'input' function and 'vector.create'. ```lua local inputMap = { -- ... drag = input { Enum.UserInputType.MouseMovement, Enum.KeyCode.Thumbstick2, [Enum.KeyCode.Left] = vector.create(-2, 0), [Enum.KeyCode.Right] = vector.create(2, 0), }, dragHold = input { Enum.UserInputType.MouseButton2 }, } ``` -------------------------------- ### Update Input Axes Every Frame (Lua) Source: https://github.com/neond00m/axis/blob/main/docs/Introduction/getting_started.md This snippet shows how to update input axes on a frame-by-frame basis using RunService.RenderStepped. It demonstrates checking for a newly pressed input and printing a message when it occurs. ```lua RunService.RenderStepped:Connect(function() attack:update() -- update the input axes if attack:pressed() then -- fires once, when the input is newly pressed print("Attacked!") end end) ``` -------------------------------- ### Mobile Pinch Gesture Integration for Zoom (Lua) Source: https://github.com/neond00m/axis/blob/main/docs/Introduction/example_game.md Connects to the UserInputService.TouchPinch event to handle zoom gestures on mobile devices. It uses a multiplier (PINCH_MULTI) to scale the pinch gesture's effect and applies it to the 'zoom' input axis. This allows for a consistent zoom experience across different input methods. ```lua local PINCH_MULTI = 50 UserInputService.TouchPinch:Connect(function(_, scale, _, _, _) -- other logic inputMap.zoom:move((scale - previousScale) * PINCH_MULTI) -- other logic end) ``` -------------------------------- ### Consolidated Input Mapping for Zoom (Lua) Source: https://github.com/neond00m/axis/blob/main/docs/Introduction/example_game.md Defines a consolidated input axis named 'zoom' that maps various input methods like DPad, keyboard keys, and mouse wheel to sensitivity values. This approach reduces the need to handle individual input types separately in other parts of the code. ```lua zoom = input { [Enum.KeyCode.DPadDown] = -2, [Enum.KeyCode.DPadUp] = 2, [Enum.KeyCode.I] = 2, [Enum.KeyCode.O] = -2, [Enum.UserInputType.MouseWheel] = 10, } ``` -------------------------------- ### Read Current and Previous Axis Values (Lua) Source: https://github.com/neond00m/axis/blob/main/docs/Introduction/getting_started.md This Lua code demonstrates how to read the current and previous values of an input axis using the 'read()' method. This is useful for inputs like the mouse wheel that have distinct states. ```lua local current, previous = zoom:read() -- current will equal either, -1, 0, or 1 -- same for previous! ``` -------------------------------- ### Handle Hold-to-Jump Input (Lua) Source: https://github.com/neond00m/axis/blob/main/docs/Introduction/example_game.md Connects to InputBegan and InputEnded events to manage the hold-to-jump functionality. It uses touch and mouse inputs to initiate and release a jump hold, returning a function to release the hold. Dependencies include Enum for UserInputType and UserInputState, and an inputMap object with a 'jump' axis. ```lua local releaseJump, touch = nil, nil jumpButton.InputBegan:Connect(function(input) if input.UserInputType ~= Enum.UserInputType.MouseButton1 and input.UserInputType ~= Enum.UserInputType.Touch then return end if input.UserInputState ~= Enum.UserInputState.Begin then return end touch = input releaseJump = inputMap.jump:hold(1) -- imitates pressing an input axis like the `Space` key -- UI effects end) UserInputService.InputEnded:Connect(function(input) if not releaseJump or input ~= touch or input.UserInputState ~= Enum.UserInputState.End then return end if input.UserInputType ~= Enum.UserInputType.MouseButton1 and input.UserInputType ~= Enum.UserInputType.Touch then return end releaseJump() -- releases the hold, imitating letting go of the `Space` key releaseJump = nil -- UI effects end) ``` -------------------------------- ### Add Thumbstick Input to Vector Axis (Lua) Source: https://github.com/neond00m/axis/blob/main/docs/Introduction/getting_started.md This Lua snippet extends a vector input axis to include controller thumbstick input. It shows how to add Enum.KeyCode.Thumbstick1, which can represent any Vector2 with a magnitude of 1. ```lua ... [Enum.KeyCode.D] = Vector2.new(1, 0), Enum.KeyCode.Thumbstick1, -- could be any Vector2 with a magnitude of 1 } ``` -------------------------------- ### Simplified Camera Zoom Clamping (Lua) Source: https://github.com/neond00m/axis/blob/main/docs/Introduction/example_game.md A simplified function to clamp the camera zoom level. This version assumes that the zoom sensitivity has already been handled by the input system, and only applies the minimum and maximum zoom constraints. This is used after consolidating input handling. ```lua local function clampZoom(zoom: number): number return math.clamp(offsetVector.Position.Z - zoom, MIN_ZOOM, MAX_ZOOM) end ``` -------------------------------- ### Handle Multiple Controller Inputs (Lua) Source: https://github.com/neond00m/axis/blob/main/docs/Devices/controller.md Iterates through all possible connected controllers (up to 8) to check for a specific input action, like pressing the jump button. This allows each player to have their own independent input handling. ```lua local function jump() for i = 1, 8 do -- if standing on the ground ... if jump:pressed(i) then -- make their character jump end end end ``` -------------------------------- ### Implement Toggleable Crouch - Luau Source: https://github.com/neond00m/axis/blob/main/docs/Introduction/example_game.md Implements the logic for a toggleable crouch mechanic. It checks for the crouch input and toggles a 'crouching' state, applying associated humanoid effects. This function is designed to work across all devices without device-specific input logic. ```luau --crouch.luau local crouching = false local function crouch(dt) -- other if statements if not inputMap.crouch:pressed() then return end crouching = not crouching -- humanoid effects end ``` -------------------------------- ### Manage Jump Hold Timer (Lua) Source: https://github.com/neond00m/axis/blob/main/docs/Introduction/example_game.md Initializes and manages a timer for how long the jump button is held. It checks the player's state to ensure jumping is possible, resets the timer if the player is not on the ground, and applies jump power and state change upon release. It increments the hold time while the button is pressed. ```lua local jumpHoldTime = 0 -- if the player is swimming or falling or climbing, reset jump power if humanoid:GetState() ~= Enum.HumanoidStateType.Running then jumpHoldTime = 0 return -- end system early end if inputMap.jump:released() then -- when the jump axis changed and is not held any more humanoid.JumpPower = getJumpPower() -- our custom equation using jumpHoldTime humanoid:ChangeState(Enum.HumanoidStateType.Jumping) jumpHoldTime = 0 return -- end early again end humanoid.JumpPower = 0 jumpHoldTime = inputMap.jump:pressing() and (jumpHoldTime or 0) + deltaTime ``` -------------------------------- ### Adjust Mouse Movement Sensitivity Source: https://github.com/neond00m/axis/blob/main/docs/Devices/desktop.md Configures the sensitivity for mouse movement input by applying a weight to `Enum.UserInputType.MouseMovement`. This example also shows combining it with controller thumbstick input for similar camera control with different sensitivities. ```lua local look = Axis.input { [Enum.UserInputType.MouseMovement] = 50, [Enum.KeyCode.Thumbstick2] = 20, -- add controller support with a different sensitivity } ``` -------------------------------- ### Handle Mobile Crouch Button - Luau Source: https://github.com/neond00m/axis/blob/main/docs/Introduction/example_game.md Connects a UI button's 'MouseButton1Down' event to trigger the crouch mechanic for mobile devices. It uses 'inputMap.crouch:move(1)' to simulate a press and toggles the 'crouching' state, updating UI effects accordingly. This demonstrates how to integrate UI input with the core input system. ```luau --touchControls.luau local crouching = false crouchButton.MouseButton1Down:Connect(function() inputMap.crouch:move(1) crouching = not crouching if not crouching then -- UI effects return end -- UI effects end) ``` -------------------------------- ### Check if Input Axis is Pressing (Lua) Source: https://github.com/neond00m/axis/blob/main/docs/Introduction/getting_started.md This Lua snippet shows how to check if an input axis is currently being pressed. The 'pressing()' method returns true if any of the associated inputs are active (equal to 1). ```lua -- if any of the above axes are equal to 1, the input is considered pressing if attack:pressing() then ... ``` -------------------------------- ### Camera Zoom Sensitivity Calculation (Lua) Source: https://github.com/neond00m/axis/blob/main/docs/Introduction/example_game.md Calculates the camera zoom level based on input device type and a predefined speed. It uses a lookup table for different device sensitivities and clamps the final zoom value within defined minimum and maximum limits. This function is part of the camera system. ```lua local ZOOM_SPEED = { Touch = 5, Gamepad = 2, Desktop = 10, } local function clampZoom(zoom: number): number return math.clamp(offsetVector.Position.Z - zoom * ZOOM_SPEED[axis.device(UserInputService:GetLastInputType())], MIN_ZOOM, MAX_ZOOM ) end ``` -------------------------------- ### Get Device Type with Axis.device() Source: https://context7.com/neond00m/axis/llms.txt Retrieves the device type (Desktop, Touch, or Controller) based on the last user input or a specified input type. Useful for adapting UI elements or game logic to different input methods. ```lua local Axis = require(game.ReplicatedStorage.Axis) local UserInputService = game:GetService("UserInputService") -- Get current device based on last input local device = Axis.device() print("Current device:", device) -- "Desktop", "Touch", or "Controller" -- Check specific input type local inputType = Enum.UserInputType.Gamepad1 local deviceType = Axis.device(inputType) print("Device type:", deviceType) -- "Controller" -- Practical example: Show appropriate UI prompts local function getButtonPrompt(action) local device = Axis.device() if device == "Desktop" then return "Press E" elseif device == "Controller" then return "Press A" elseif device == "Touch" then return "Tap Button" end end -- Update UI when input device changes UserInputService.LastInputTypeChanged:Connect(function(lastInputType) local device = Axis.device(lastInputType) print("Switched to:", device) -- Update all UI prompts updateAllPrompts(device) end) ``` -------------------------------- ### Detect Input Axis Press Event (Lua) Source: https://context7.com/neond00m/axis/llms.txt Returns whether the axis was activated this frame (changed from inactive to active). Useful for detecting the initial press of a button, triggering actions like jumping or starting an attack. ```lua local Axis = require(game.ReplicatedStorage.Axis) local jump = Axis.input { Enum.KeyCode.Space, Enum.KeyCode.ButtonA, } local attack = Axis.input { Enum.KeyCode.E, Enum.UserInputType.MouseButton1, Enum.KeyCode.ButtonX, } game:GetService("RunService").RenderStepped:Connect(function() jump:update() attack:update() -- pressed() fires only once when input begins if jump:pressed() then print("Jump initiated!") -- Trigger jump logic here end if attack:pressed() then print("Attack started!") -- Play attack animation, deal damage, etc. end end) ``` -------------------------------- ### Create Input Axis with Axis.input (Lua) Source: https://context7.com/neond00m/axis/llms.txt Demonstrates creating various input axes using Axis.input. This function takes a keymap to define input sources, weights, and types (scalar or vector). It supports custom deadzones and sensitivity. ```lua local Axis = require(game.ReplicatedStorage.Axis) -- Simple scalar input (default weight of 1) local attack = Axis.input { Enum.KeyCode.E, Enum.UserInputType.MouseButton1, Enum.KeyCode.ButtonR2, -- Xbox/PS controller trigger } -- Weighted scalar input local zoom = Axis.input { [Enum.KeyCode.I] = 2, -- Zoom in with weight 2 [Enum.KeyCode.O] = -2, -- Zoom out with weight -2 [Enum.UserInputType.MouseWheel] = 10, -- Mouse wheel with multiplier } -- Vector input for 2D movement local move = Axis.input { [Enum.KeyCode.W] = Vector2.new(0, 1), [Enum.KeyCode.S] = Vector2.new(0, -1), [Enum.KeyCode.A] = Vector2.new(-1, 0), [Enum.KeyCode.D] = Vector2.new(1, 0), Enum.KeyCode.Thumbstick1, -- Controller thumbstick (auto-detected as vector) } -- Camera input with sensitivity settings local look = Axis.input { [Enum.UserInputType.MouseMovement] = 50, -- Mouse with sensitivity 50 [Enum.KeyCode.Thumbstick2] = 20, -- Right stick with sensitivity 20 } -- Input with custom deadzone for controller local movement = Axis.input { Enum.KeyCode.Thumbstick1, deadzone = 0.2, -- Custom deadzone (default is 0.3) } ``` -------------------------------- ### Define Simple Keyboard Axis Source: https://github.com/neond00m/axis/blob/main/docs/Devices/desktop.md Creates a basic input axis using a single keyboard key. This is useful for simple actions like attacking or interacting. It relies on the `Axis.input` function and `Enum.KeyCode`. ```lua local attack = Axis.input { Enum.KeyCode.E, } ``` -------------------------------- ### Define Multiple Input Axes in Lua Module Source: https://github.com/neond00m/axis/blob/main/docs/Introduction/best_practices.md Shows how to define multiple input axes (inputDelta, attack, block) within a Lua module using Axis. This approach centralizes input definitions for easier management and access across different systems. ```lua local inputMap = { inputDelta = Axis.input { Enum.UserInputType.MouseMovement, [Enum.KeyCode.Thumbstick1] = 20, }, attack = Axis.input { Enum.KeyCode.E, Enum.KeyCode.ButtonA, }, block = Axis.input { Enum.KeyCode.F, }, } return inputMap ``` -------------------------------- ### Define Single Input Axis in Lua Source: https://github.com/neond00m/axis/blob/main/docs/Introduction/best_practices.md Demonstrates how to define a single input axis for mouse movement and thumbstick input using Axis in Lua. This is a basic building block for input handling. ```lua local inputDelta = Axis.input { Enum.UserInputType.MouseMovement, [Enum.KeyCode.Thumbstick1] = 20, } local function camera() ... end ``` -------------------------------- ### Implement Aiming Input with Hold() for Touch Source: https://github.com/neond00m/axis/blob/main/docs/Devices/touch.md This snippet shows how to set up an input axis for aiming using Axis.input and then control it with touch input via the hold() method. It connects a UI button's touch events to the 'aim' input axis, simulating a hold action when the button is pressed and releasing it when the touch ends. This allows for continuous input while enabling camera dragging. ```lua local aim = Axis.input { Enum.UserInputType.MouseButton2, Enum.KeyCode.ButtonL2 } local function aimDownSights() aim:update() local isAiming: number = if aim:pressed() then 1 else 0 local gunOffset = hipOffset:Lerp(aimOffset, isAiming) ... end local release, touch = nil, nil -- Assuming aimButton is a UI element aimButton.InputBegan:Connect(function(input) if input.UserInputType ~= Enum.UserInputType.MouseButton1 and input.UserInputType ~= Enum.UserInputType.Touch then return end if input.UserInputState ~= Enum.UserInputState.Begin then return end touch = input release = aim:hold() -- this sets the value of the aim input to 1, as if there was a right click end) UserInputService.InputEnded:Connect(function(input) if not release or input ~= touch or input.UserInputState ~= Enum.UserInputState.End then return end if input.UserInputType ~= Enum.UserInputType.MouseButton1 and input.UserInputType ~= Enum.UserInputType.Touch then return end release() -- this releases the hold, as if the right click was released release = nil end) ``` -------------------------------- ### Combine Keyboard and Mouse Inputs Source: https://github.com/neond00m/axis/blob/main/docs/Devices/desktop.md Creates a single input axis that can be triggered by multiple input types, including keyboard keys, mouse buttons, and controller buttons. This allows for flexible control schemes. It uses `Axis.input` with a mix of `Enum.KeyCode` and `Enum.UserInputType`. ```lua local attack = Axis.input { Enum.KeyCode.E, Enum.UserInputType.MouseButton1, Enum.KeyCode.ButtonR2, -- add controller support too! } ``` -------------------------------- ### Define Mouse Button Axis Source: https://github.com/neond00m/axis/blob/main/docs/Devices/desktop.md Sets up an input axis triggered by a mouse button. This uses `Axis.input` and `Enum.UserInputType.MouseButton1` for primary click actions. ```lua local shoot = Axis.input { Enum.UserInputType.MouseButton1, } ``` -------------------------------- ### Utilize Input Map for Game Logic (Luau) Source: https://context7.com/neond00m/axis/llms.txt This Luau script demonstrates how to use the centralized input map within a game's client-side logic. It updates all inputs each frame using `Axis.update()`, then reads specific axes like movement and camera delta, and checks for action button presses (jump, attack, block). It also shows how to detect the current device for potential UI adjustments. ```luau -- main.client.luau (usage) local RunService = game:GetService("RunService") local Axis = require(game.ReplicatedStorage.Axis) local inputMap = require(script.Parent.inputMap) RunService.RenderStepped:Connect(function(dt) -- Update all inputs at once Axis.update(inputMap) -- Movement local moveDir = inputMap.move:read() local isSprinting = inputMap.sprint:pressing() -- Camera local lookDelta = inputMap.look:read() -- Actions if inputMap.jump:pressed() then -- Handle jump end if inputMap.attack:pressed() then -- Handle attack end if inputMap.block:pressing() then -- Handle blocking (continuous) end -- Device-specific UI local device = Axis.device() -- Update prompts based on device... end) ``` -------------------------------- ### React Component for Glossary Item Source: https://github.com/neond00m/axis/blob/main/docs/intro.mdx Defines a reusable React component 'Item' to display glossary entries. It takes title, description, and id as props and renders them within a card structure, including a direct link to the section. ```javascript import Link from "@docusaurus/Link"; export const Item = ({ title, description, id }) => (