c# – How do I increase my jump speed in Unity 3D?

Question:

There is a jump script. He is a worker. It works only when the character is on the ground, but I am not satisfied with the speed with which he falls, you need to increase it, how to do it? Clarification: you need to keep the same jump height, but increase the speed with which he will cover this distance.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Jump : MonoBehaviour
{
    public Rigidbody Player;
    public float ForceJump = 10f;
    private bool IsGround = false;

    void Start()
    {
        Player = GetComponent<Rigidbody>();
    }
    
   void OnTriggerStay(Collider col)
    {
       if (col.tag == "Ground")
       {
           IsGround = true;
           
       }
    }

    void OnTriggerExit(Collider col)
    {
        if (col.tag == "Ground")
        {
            IsGround = false;
            
        }
    }

   
   void OnMouseDown()
    {
        Debug.Log("Нажатие");
        if (IsGround == true)
        {
            Debug.Log("IsGround == true");
            Vector3 ImpulsePlayer = new Vector3(0, ForceJump, 0);//Направление импульса
            Player.AddForce(ImpulsePlayer, ForceMode.Impulse);//Импульс
        }
    }
}

Answer:

internal class Example : MonoBehaviour
{
    [SerializeField]
    private AnimationCurve animation;

    private float ExpiredTime;
    private float Duration = 1;
    private float Height = 5;

    private void Update()
    {
        ExpiredTime += Time.deltaTime;

        if (ExpiredTime > Duration)
            ExpiredTime = 0;

        float progress = ExpiredTime / Duration;

        transform.position = new Vector3(0, animation.Evaluate(progress), 0);
    }
}
Scroll to Top
AllEscort