- Home /
How to use Multi-Tap in New Input System for Running?
Hi, I'm working on a game, where the player collects Trash from Trash cans and puts it in a Trash Truck. I'm trying to get controller / multiple-device support to work for my game, however, I've ran into some issues, as the character controller I'm using is an asset. I have gotten almost every other movement interaction working, except, controller-running / sprinting. I'm trying to use Multi-Tap, however, I do not know how to use it. Here's what I have so far: The name of the script is MultInput. I have a reference to this in the Asset's Script called MultInt. Also, the asset in question is called First Person All-In-One. Here's the MultInput Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Interactions;
public class MultInput : MonoBehaviour
{
#region newscript
public PlayerControls controls;
public float primVal;
public float secVal;
public float randKey;
public float equipKey;
public float jumpKey;
public float crouchKey;
public float unflipKey;
public float sprintKey;
public Vector2 move;
public Vector2 m;
void Awake()
{
controls = new PlayerControls();
controls.Gameplay.Primary.performed += ctx => primVal = ctx.ReadValue<float>();
controls.Gameplay.Primary.canceled += ctx => primVal = 0.0f;
controls.Gameplay.Secondary.performed += ctx => secVal = ctx.ReadValue<float>();
controls.Gameplay.Secondary.canceled += ctx => secVal = 0.0f;
controls.Gameplay.RandKey.performed += ctx => randKey = ctx.ReadValue<float>();
controls.Gameplay.RandKey.canceled += ctx => randKey = 0.0f;
controls.Gameplay.EquipKey.performed += ctx => equipKey = ctx.ReadValue<float>();
controls.Gameplay.EquipKey.canceled += ctx => equipKey = 0.0f;
controls.Gameplay.Jump.performed += ctx => jumpKey = ctx.ReadValue<float>();
controls.Gameplay.Jump.canceled += ctx => jumpKey = 0.0f;
controls.Gameplay.Crouch.performed += ctx => crouchKey = ctx.ReadValue<float>();
controls.Gameplay.Crouch.canceled += ctx => crouchKey = 0.0f;
controls.Gameplay.UnflipKey.performed += ctx => unflipKey = ctx.ReadValue<float>();
controls.Gameplay.UnflipKey.canceled += ctx => unflipKey = 0.0f;
controls.Gameplay.SprintKey.performed += ctx => sprintKey = ctx.ReadValue<float>();
controls.Gameplay.SprintKey.canceled += ctx => sprintKey = 0.0f;
controls.Gameplay.Up.performed += ctx => move = ctx.ReadValue<Vector2>();
controls.Gameplay.Up.canceled += ctx => move = Vector2.zero;
}
bool m_Dash;
void OnMoveLeft(InputAction.CallbackContext context)
{
if (!context.performed)
return;
if (context.interaction is MultiTapInteraction)
m_Dash = true;
Debug.Log("Sprinting");
}
void PrimButton()
{
Debug.Log("Primary Button!");
}
void Update()
{
Debug.Log("Primary Value: " + primVal);
Debug.Log("Secondary Value: " + secVal);
Debug.Log("RandKey Value: " + randKey);
Debug.Log("EquipKey Value: " + equipKey);
Debug.Log("JumpKey Value: " + jumpKey);
Debug.Log("CrouchKey Value: " + crouchKey);
Debug.Log("UnflipKey Value: " + unflipKey);
Debug.Log("SprintKey Value: " + sprintKey);
Debug.Log("Move Up Value: " + move);
m = new Vector2(-move.x, move.y);
Debug.Log("Move Up M: " + m);
}
void OnEnable()
{
controls.Gameplay.Enable();
}
void OnDisable()
{
controls.Gameplay.Disable();
}
#endregion
}
And I have this bit of code for the FPSAIO Script, isSprinting is something that appears to be that it needs to be true in order for the player to run:
if(multInt.sprintKey == 0.0f)
{
isSprinting = false;
}
else if(multInt.sprintKey == 1.0f)
{
isSprinting = true;
}
Here's what I have in the Console Output for the MultInput Script whenever I try to use Multi-Tap:
I'm pretty sure I've covered everything, I hope I have, at least. If anyone needs any more information, please, let me know! Thanks!
Answer by Komoszeskito · Apr 28 at 11:30 AM
Hello
I think you can use,
action.WasPerformedThisFrame();
or even better:
action.triggered
For example, let's say the action is bound to the space bar and that the binding has a
assigned to it. In the frame where the space bar is pressed, will be true (because the button/key is now pressed) but WasPerformedThisFrame will still be false (because the hold has not been performed yet). Only after the hold time has expired will WasPerformedThisFrame be true and only in the frame where the hold performed.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Simultaneous touch inputs do not always work 0 Answers
How to reference New InputSystem Input Values in C# Script? 1 Answer