Click here to Skip to main content
15,667,010 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want my gameobjects to fall faster by time as the player collides with them. What I mean is, when the game starts, the gameobjects fall off after 1 second the player collided with them, but after 60 seconds, gameobjects only fall after 0.3 seconds after the player has been collided with them.
The idea is to give the player less time to jump from a platform (gameobject) to another platform as the time goes, so it will be more challenging.
Here is what I've made so far:
private Rigidbody rb;
    public float currentFallDelay = 1f;
    float minFallDelay = 0.3f;
    public float accelerationTime = 10;
    private float maxFallDelay;
    private float time;

    void Start()
        rb = GetComponent<Rigidbody>();
        minFallDelay = currentFallDelay;
        time = 0;

    public IEnumerator FallDelay()
        rb.isKinematic = true;
        yield return new WaitForSeconds(1f);
        while (true)
            currentFallDelay = Mathf.SmoothStep(minFallDelay, maxFallDelay, time / accelerationTime);
            transform.position += Vector3.down * currentFallDelay * Time.deltaTime;
            time += Time.deltaTime;
            yield return null;

    void OnCollisionEnter(Collision col)

        if (rb.isKinematic && col.collider.CompareTag("Player"))


What I have tried:

I tried to use yield return new WaitForSeconds(1f) inside FallDelay() but of course it didn't change the fall delay after time.

Can anyone help me how to fix that?
Helps are appreciated!
Gerry Schmitz 6-Jan-22 1:26am    
The frame rate is constant. To increase the fall rate, you increase the distance covered during a frame update cycle. The delays and while loop makes no sense in this context.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900