Hello all,
I’m having some issues getting my method for double tapping either horizontal direction buttons to increase the speed of the character. It worked before when I just had it under Update but after moving it to it’s own method it stopped working. I’m not sure why. Relevant code snippets below:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.U2D;
public class CharacterController2D : MonoBehaviour
{
private float horizontalInput = 0f;
private float Initialspeed = 5.0f;
[SerializeField] private float runMultiplier = 1.5f; // Multiplier for run speed
private bool isRunning = false;
private float lastTapTime = 0f;
private const float doubleTapTimeThreshold = 0.3f;
void FixedUpdate()
{
DoubleTapToRun();
// Calculate current movement speed
float currentSpeed = Initialspeed * (isRunning ? runMultiplier : 1.0f);
// Apply horizontal movement
rb.velocity = new Vector2(horizontalInput * currentSpeed, rb.velocity.y);
}
private void DoubleTapToRun()
{
if (Input.GetButtonDown("Horizontal"))
{
if (Time.time - lastTapTime < doubleTapTimeThreshold)
{
isRunning = true;
Debug.Log("Run activated! 1.5 times");
}
else
{
isRunning = false; // Deactivate run when no double tap
}
lastTapTime = Time.time;
}
else
{
isRunning = false; // Deactivate run when direction not held
}
}
}
I’ve tried moving the DoubleTapToRun() reference into Update to see if that would help with no change. Not sure what else to try. I’ve been staring at this for like an hour and I think my brain is starting to get fried lol
The rest of the code isn’t relevant in my opinion but if someone wants to see it then I’d be happy to share the full code. It’s only 139 lines so it’s not that long right now.