Answers for "how to gradually increase speed unity"

C#
1

how to gradually increase speed unity

using UnityEngine;

public class example : MonoBehaviour
{

public float acceleration = 5f; // how much you want object to accelerate 
public float maxSpeed = 20f; // maximum speed the object can reach
private float curSpeed = 0f; // the Current speed of the object

void Update ()
{
  Move();
curSpeed += acceleration * Time.deltaTime;
if (curSpeed > maxSpeed)
{
curSpeed = maxSpeed;
}

}

void Move()
{

transform.Translate = (Vector3.right * curSpeed); // gradually increases speed of object as it moves right

}
Posted by: Guest on October-07-2021

Code answers related to "how to gradually increase speed unity"

C# Answers by Framework

Browse Popular Code Answers by Language