I want my character to accelerate from one speed to another, but I have no idea how to.
I plan on having a minimum speed (speed) a maximum speed (maxSpeed) and an amount of time to accelerate to max speed (accelTime).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Move3D : MonoBehaviour
{
public float speed;
public float jump;
protected bool newInput;
public CharacterController move;
public float maxSpeed;
public float accelTime;
private Vector3 moveDirection;
public float gravity;
void Start()
{
move = GetComponent();
}
void LateUpdate()
{
float yStore = moveDirection.y;
moveDirection = (transform.forward * Input.GetAxis(“Vertical”)) + (transform.right * Input.GetAxis(“Horizontal”));
moveDirection = moveDirection.normalized * speed;
moveDirection.y = yStore;
if (move.isGrounded)
{
moveDirection.y = 0f;
if (Input.GetButtonDown(“Jump”))
{
moveDirection.y = jump;
}
}
moveDirection.y = moveDirection.y + (Physics.gravity.y * gravity * Time.deltaTime);
move.Move(moveDirection * Time.deltaTime);
}
}
Any idea how I can insert it in here? Thanks.