Using animationcurves for controlling jump height through charactercontroller.Move()

Hey Guys :slight_smile:

I’m trying to create a nicer and easier customizable flow for my jump.
But I have no idea how to do this.

This is currently my code for the jump:

case PlayerState.jumping:
			
	moveDirection = new Vector3(0,currentJumpSpeed,0);
			
	playerController.Move(moveDirection);
	currentJumpSpeed -= jumpSpeedFalloff;
			
	break;

Nothing exciting, however what I want is to control the value of the falloff with a curve :slight_smile:

Any good suggestions? :slight_smile:

Hey again, so with the help I got from TheValar, I ended up getting what I wanted :3
It’s nothing special but I thought I’d share it anyway ^^

alt text

So this is my inspector view, and what I did was making a public animation curve along with my jump speed

Here’s the code:

if(Input.GetAxisRaw("X") >= 0.1f){
	currentState = PlayerState.jumping;
	jumpTimer = 0.0f;
}

//-----------------------------------------------------------------

case PlayerState.jumping:
			
	moveDirection = new Vector3(0,currentJumpSpeed,0);
			
	playerController.Move(moveDirection);
	jumpSpeedFalloff = jumpCurve.Evaluate(jumpTimer);
	currentJumpSpeed -= jumpSpeedFalloff;
	jumpTimer += Time.deltaTime;
			
	break;

I hope someone else can make use of this because this was a topic which took me a long time to understand <.<’

My curve looks like that because I’m trying to have a fast setoff, which degrades quickly, then go on to having the character more or less floating for a while, then go back to having a fast descend :3

I’ve never done this but I don’t see why it wouldn’t be possible to do the following.

Add a public AnimationCurve variable to your controller script and edit it to your desire Unity - Manual: Editing Curves

Then from your script you can sample the appropriate part of the curve using jumpSpeedFalloff = curve.Evaluate(timeSinceJumpStarted); or something