I have a little bug in my game and I want to be sure that no one can use this.
I let the CharacterController shrink and get bigger with a Mathf.Lerp function.
that works fine but I want that he stands up slow and get faster till the endsize…
I thought I could use a animation curve to solve this problem but I dont know how to use one and I dont find something useful un the internet.
here is the code I use for the crouch uncrouch so that the character dont fall through the ground.(the code is not complete I just copied the important parts)
function Awake()
{
chMotor = GetComponent (PlayerMotor);
ch = GetComponent (CharacterController);
tr = transform;
height = ch.height;
}
function FixedUpdate()
{
var h = height;
if (isCrouching == true)
{
h = 0.5 * height;
}
var lastHeight = ch.height;
ch.height = Mathf.Lerp(ch.height, h, 6*Time.deltaTime);
tr.position.y += (ch.height - lastHeight)/2;
}
There is a script on this post that uses an animation curve to control a light:
http://answers.unity3d.com/questions/382628/flashlight-battery-script.html.
The basic idea:
- Create a public variable of type AnimationCurve in your script.
- In the inspector click on the curve and modify it to the shape you need.
- In your source use Evaluate() with values between 0.0 and 1.0. You get back the height of the curve at that point.