Hi everybody,
so i have this problem of inconsistent jump that comes mostly (but not systematically) when there is a double tap (double jump), the game is intented for mobile.
The relevant pieces of code here
public class Player : MonoBehaviour
{
float timer;
float moveLimiter = 2f;
float waitTime = 0.1f;
float count = 0;
float speed = 7f;
[SerializeField] private AudioSource jumpSoundEffect;
Touch touch;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
jumpNumber = 0;
isJumping = true;
waitTime = 0.1f;
vertical = 0;
}
void Update()
{
bottom = new Rect(0, 0, Screen.width, Screen.height / 4);
top = new Rect(0, Screen.height / 4, Screen.width, Screen.height / 1.35f);
if (timer >= waitTime )
// The timer is needed because i want the jump to be a one-time jump only, and not a continuous movement.
{
vertical = 0;
}
if (!isJumping)
{
if (Input.touchCount > 0)
{
touch = Input.GetTouch(0);
if (top.Contains(touch.position) && !isJumping )
{
vertical = speed;
isJumping = true;
}
else if (bottom.Contains(touch.position) && !isJumping)
{
vertical = -speed;
isJumping = true;
}
}
}
else
{
if (timer >= waitTime)
// The timer is needed because i want the jump to be a one-time jump only, and not a continuous movement.
{
count++;
timer -= waitTime + Time.fixedDeltaTime;
print($"lapsed {waitTime}");
print($"And count is {count}");
timer = 0f;
waitTime = 0.1f;
isJumping = false;
}
}
void FixedUpdate()
{
if (isJumping) { timer += Time.fixedDeltaTime; }
rb.velocity = new Vector2(0, vertical * playerSpeed);
}
Illustration of the problem in a video : az_recorder_20230813_145322.mp4 - Google Drive
Illustrations of the problem in pictures :
Any idea/hint on how to deal with this problem ?
I tried googling similar problems/responses from this forum, but since the cases i found don’t use a timer it can hardly be extrapolated to my own code.

