Simple jump loop

Hello, I just want to make a jump effect with script but my loop is too fast so I don’t see anything at the screen. Someone has an idea to fix this :)?

jumpResult = 500;
jump();

void jump() {
 for (int i=0; i<=18; i++)
 {
    jumpResult-= 50;
 transform.Translate(0,jumpResult,0);
 Debug.Log(jumpResult);
 }
 jumpResult = 500;
 jumpCount=0;
 }

Thanks in advance !

You could add ‘yield WaitForSeconds(0.2);’ (change the value to your liking) inside the loop, to make it slower, although I would write a jump function completely different (with physics and Rigidbody.velocity).

You need to multiply your units by deltaTime.
I didn’t test this code, but something like

   Vector 3 jump = Vector3.zero;
    
    void Update() {
        if (jump != Vector3.zero) {
            Vector3 positionNow = transform.position;
            positionNow += jump;
            transform.position = positionNow;
    
            jump.y -= 10.0f * Time.deltaTime; // Move down 10 frames every second
        }
    }
    
    void Jump() {
        jump.y = 500.0f;
    }

You need to multiply your jump value by deltaTime

float jumpHeight = 0.0f;

void Update() {
position.y = jumpHeight;
if (jumpHeight != 0.0f) {
jumpHeight -= 10.0f * Time.deltaTime; // Will fall 10 units per second
if (jumpHeight < 0) jumpHeight = 0.0f
}

void Jump() {
jumpHeight = 50.0f; // Will take 5 seconds to fall
}

I will test it soon :slight_smile: