Question by
Paliandro · Apr 05, 2018 at 09:58 AM ·
c#movementvisual studioacceleration
Cumulative acceleration for copies.
So, right now I have a code that accelerates items as they move across the screen, they all start from the same speed and accelerate. What I would like to happen is for the next item starting from the accelerated speed of the last one. It's probably very simple but my head is in a knot.
public class Mover : MonoBehaviour {
public float speed;
public float maxSpeed;
public float accelTime;
private float minSpeed;
private float time;
private void Start()
{
minSpeed = speed;
time = 0;
}
private void Update()
{
speed = Mathf.SmoothStep(minSpeed, maxSpeed, time / accelTime);
GetComponent<Rigidbody2D>().velocity = transform.right * speed;
time += Time.deltaTime;
}
}
Comment
Tried more stuff and still haven't gotten it to work, to reword the question: How can I get the speed of an object as it is destroyed to be inherited as the starting speed of the next instantiated copy of it?