Hi,
i need help, my programing looks ctrl+c and ctrl+v but when i read codes i understand relatively…
this is my problem, i need give automatic gradual acceleration to code, which is below…
using UnityEngine;
using System.Collections;
public class Mover : MonoBehaviour
{
public float speed;
private Rigidbody rb;
When people usually think of ‘speed’, they are actually referring to their max velocity. So instead of setting velocity to speed all at once, you’ll need to slowly add to velocity. This is called acceleration.
float speed = 5f; // max velocity
float acceleration = 0.1f; // how fast to increase velocity
float velocity = 0f;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
// add to velocity
velocity += acceleration;
// check if we are at our top speed
if (velocity > speed) {
velocity = speed;
}
// then set it to rb
rb.velocity = new Vector3(0f, velocity, 0f);
}