- Home /
Using animationcurves for controlling jump height through charactercontroller.Move()
Hey Guys :)
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 :)
Any good suggestions? :)
Answer by Kenned · Nov 07, 2013 at 11:26 AM
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 ^^
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
this will be useful! especially the animationcurve will be handy for other situation :)
and I'm bad at math, lol
Answer by TheValar · Nov 06, 2013 at 02:12 PM
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 http://docs.unity3d.com/Documentation/Components/EditingCurves.html
Then from your script you can sample the appropriate part of the curve using jumpSpeedFalloff = curve.Evaluate(timeSinceJumpStarted); or something http://docs.unity3d.com/Documentation/ScriptReference/AnimationCurve.Evaluate.html
Thanks a bunch : D I'll try it out in a few $$anonymous$$utes when I get my particle system up and running as it should :)
It sounds like it should do the trick :P
I'd be interested in how this turns out. If you get it working you should post a video or a webplayer.
Sure :3 I'll come back to that, we're currently working with a deadline for monday so I have quite a few elements that needs fixing, but I'll probably get to fix it later today :)