I have a capsule in my scene that I want to make a jump on a button press. It has to look smooth too. Rigidbody + addforce is not an option.
The height the capsule has to jump is also randomized.
var jumpHeight = Random.Range(0.0,1.5);
So basically when jumpHeight is 0.7, the capsule has to jump 0.7 in air and back to the ground.
You can calculate the position of your GO for the jump and make it translate to that position based on time.
For more details on how to calculate the parabolic path of the jump go through the links provided in answer to this question: How to move object parabolic projectile path
It’s just that you calculate the position of your object using the parabolic path equation and move your GO to appropriate position based on time by putting the appropriate values in that equation and getting the position to move your object to.
This is for the case when you don’t want to use rigidbody+addForce to move your GO.
You can use a sine wave and lerp the values. 180 degrees (or PI radians) will give you one half of a sine wave, or a little jump so to speak. For example:
void Update_Jump()
{
time += Time.deltaTime;
float timer = time / k_JumpTime;
if(timer > 1.0f)
return;
float y = Matf.Sin(timer * Math.PI) * jumpHeight;
gameObject.transform.position.y = y;
}