I’m trying to propel my character forward with the spacebar. So I set a force as a vector3, and a charactercontroller, and when the spacebar is pressed, I enter a while(force is more than 0) loop. In the loop, I move forward by whatever force is equal to, and then subtract a little from force. The result is an abrupt, 1-frame motion that I’m looking to change to a several frame motion with a smooth stop. Can anybody give me a hint on how to do this?
Here’s that chunk of my code IF IT HELPS:
CharacterController cont;
Vector3 force;
void Start()
{
cont = GetComponent<CharacterController> ();
force = (new Vector3(0,0,1f) * Time.deltaTime);
}
void Update ()
{
if (Input.GetButtonDown ("Boost"))
{
while(force.z > 0)
{
cont.Move (force);
force.z -= (0.1f) * Time.deltaTime;
}
}