- Home /
Increase speed over time enemy
Hi there, i am trying to create a enemy who spawns and move towards y position with my knowledge i got this.I can move the object on Y position, but cant make it increase speed over time.
private Rigidbody2D rb2d;
public float speedIncrement = 10f;
public float maximumSpeed = 70f;
public float speed = 2;
public float scroolSpeed1 = 2;
void Start()
{
////Get and store a reference to the Rigidbody2D attached to this GameObject.
rb2d = GetComponent<Rigidbody2D>();
////Start the object moving.
rb2d.velocity = new Vector2(0, 1) * scroolSpeed1;
}
void FixedUpdate()
{
scroolSpeed1 += speedIncrement;
if (scroolSpeed1 <= maximumSpeed) scroolSpeed1 = maximumSpeed;
}
Comment
Answer by badadam · Jan 10, 2019 at 07:11 PM
rb2d.velocity = new Vector2(0, 1) * scroolSpeed1; this command line must be in FixedUpdate method after you increase speed
void FixedUpdate()
{
scroolSpeed1 += speedIncrement;
if (scroolSpeed1 <= maximumSpeed) scroolSpeed1 = maximumSpeed;
rb2d.velocity = new Vector2(0, 1) * scroolSpeed1;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612185517im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Speed = 11 meters /s plane is 110 meters should take me 10 seconds but it dosn't 0 Answers
Accelerate/Decelerate Custom Game Clock 2 Answers
How To Add A Simple Speed Boost On Collision With A Specific Object With A Character Controller 0 Answers
Problem with time !! help me 1 Answer
Increase variable for a few seconds 2 Answers