I have a working Jump Script, but the Jump is not as Snappy as I need.
I want the Player to Jump immidiately, not Float up a bit and then Jump, like in Version 0.0.2 of [the Game I'm speaking](https://gamejolt.com/games/sosasees-1st-2d-platformer/343471).
---
The Jump Script has only the Jump Functions and not the Walk Functions, because I separated the Jump and Walk Scripts. Here is the Jump Script:
---
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test2PlayerJump : MonoBehaviour {
public Rigidbody2D rb2d;
public float JumpForce;
public float MaxTime;
private float CurrentTime;
private bool Grounded;
public bool CanHoldJump;
// Use this for initialization
void Start () {
rb2d = GetComponent();
JumpForce = 30;
MaxTime = 0.25f;
CurrentTime = MaxTime;
Grounded = true;
CanHoldJump = true;
}
// Update is called once per frame
void Update () {
if (CanHoldJump == true)
{
if (CurrentTime >= 0)
{
rb2d.AddForce(new Vector2(0, Input.GetAxis("Jump")) * JumpForce * Time.deltaTime, ForceMode2D.Impulse);
CurrentTime -= Time.deltaTime;
}
}
else if (Grounded == false)
{
CanHoldJump = false;
}
if (Grounded == true)
{
CurrentTime = MaxTime;
}
}
private void OnCollisionStay2D(Collision2D collision)
{
if (collision.gameObject.tag == "Ground")
{
Grounded = true;
CanHoldJump = true;
}
↧