- Home /
Inconsistent jump height
I'm using a coroutine to jump like in this tutorial :
https://www.gamasutra.com/blogs/DanielFineberg/20150825/244650/Designing_a_Jump_in_Unity.php
it adds a decreasing force in the coroutine while you jump, this is my first time using a coroutine for a jump so im not sure why the jump height changes.
Answer by GeroNL · Mar 09, 2021 at 11:21 PM
Maybe you should debug the proportion force, before it do addforce. Then check several time, are the values give same value)?
and i see the sample in the website that you attach, your concept that you use is The Just Right right? i did not see it's give same height jump.
maybe you can try it by learping to the height you want, multiple it by curve for acceleration, and do the down after jump too, then give max to gravity * time.deltatime when it's still falling.
You're right, the proportion force isn't consistent. Do you have any resources on how to implement the jump you described or could you give me some pointers? I'm new to unity so I'm not sure how to multiply it by acceleration or how to handle gravity.
try like this :
public AnimationCurve curveJump;
public float maxHeightJump = 2;
public float jumpPower = 5;
private float tempY;
....
private void Jump()
{
isJump=true;
tempY= player.transform.position.y + maxHeightJump;
}
// in update
if(is on ground and isJump)
{
if(player.transform.position.y <tempY )
{
player.transform.position.y = jumpPower * curveJump.Evaluate((player.transform.position -tempY)/maxHeightJump ) *Time.deltaTime;
}
else if(player.transform.position.y >= tempY )
{
isInJump = false;
}
}
if(is not on ground and !isJump)
{
//do it same like jump but reverse it, make it simple first for undestanding the movement
}
Put grafik in aniationCurve, for jump give start point 1 then final point 0, then for fall is 0 - 1.
Try to know about this first :
player.transform.position.y = jumpPower * curveJump.Evaluate((player.transform.position -tempY)/maxHeightJump ) *Time.deltaTime;
// or you can put update it without condition, what will this doing
player.transform.position.y = jumpPower * Time.deltaTime;
// Curve is just make different movement but will arrive on destiny in the same time. this is what i know about interpolation.
idk, is a correct one or not, but that was a concept i did. Hope it can help.
Thank you so much! Your code really helped explain what an animation curve is, the way i understand it now is its basically a non linear lerp. Ill study up on it some more and try to code it.
Your answer
![](https://koobas.hobune.stream/wayback/20220613030444im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Better jumping with "Lerpz" character controller 1 Answer
Can't Modify PlatformerCharacter2D Jump Force From Other Script 0 Answers
Jump Code Not Working (2D C#) 2 Answers
How do I get the character to jump in a 2d game, which is compatible with joysticks and keyboards? 0 Answers
Improvements to Jumping 1 Answer