Aiming with Gamepad Right Stick
🔥
7
💡
3
👏
2
This add-on allows you to aim using a gamepad’s right stick.
All the changes will be made to the PlayerController.cs script.
- Anywhere in the
OnStartmethod, add:
GameManager.InputSystem.gameplay.point.performed += OnPoint;
- Anywhere in the
OnStopmethod, add:
GameManager.InputSystem.gameplay.point.performed -= OnPoint;
- Anywhere under the
PlayerController.csscript, add the following method:
private void OnPoint(InputAction.CallbackContext context)
{
if (!m_castAbilitiesInPointerDirection) return;
if (context.control.device is Pointer)
{
Vector2 pointerPosition = context.ReadValue<Vector2>();
Vector2 mousePosWorld = Camera.main.ScreenToWorldPoint(pointerPosition);
Vector2 characterToMouseDir = (mousePosWorld - (Vector2)m_interactionPivot.transform.position).normalized;
m_subject.SetTargetDirection(characterToMouseDir);
}
else
{
Vector2 direction = context.ReadValue<Vector2>();
if (direction.magnitude > 0.2f)
{
m_subject.SetTargetDirection(direction.normalized);
}
}
}
- Find the
OnUpdatemethod and replace it with:
protected override void OnUpdate()
{
m_interactedThisFrame = false;
m_interactionTarget = GetInteractibleObject();
if (!m_castAbilitiesInPointerDirection)
{
m_subject.ResetTargetDirection();
}
}
Find input settings in
Assets/Mythril2D/Demo/Settings/PlayerInputActionsand double click on it.under the “Gameplay” action map, find the “Move” action. Copy the “Left Stick [Gamepad]” action and paste it under “Point”.
Click on the newly created action, and edit the “Path” value from “Left Stick [Gamepad]” to “Right Stick [Gamepad]”.
Save the asset (top right of the window)
Enjoy!

💬 Comments (1)
Want to continue the conversation?