Unity C# Tutorial | Simple Rocket Launch Script
![Unity C# Tutorial | Simple Rocket Launch Script](https://digitalpress.fra1.cdn.digitaloceanspaces.com/e5q1bl6/2022/09/screen_2560x1440_2020-08-20_16-21-32-1.png)
Here I will show you how to make a simple rocket launch script. You can use any rocket model since this script only needs one game object. I used this Low Poly Rocket Launch Complex asset for this tutorial. You can get it here on the Unity asset store if you want to use the same asset.
![](https://digitalpress.fra1.cdn.digitaloceanspaces.com/e5q1bl6/2022/10/unity-5.jpg)
![](https://digitalpress.fra1.cdn.digitaloceanspaces.com/e5q1bl6/2022/10/ezgif.com-gif-maker--1-.gif)
Script
Variables
speed
: Initial launch speedacceleration
: acceleration value per secondmaxSpeed
: maximum rocket speed
Update method
transform.Translate(Vector3.up*speed*Time.deltaTime, Space.World);
: Moves the transform in the direction and distance of translation
. We move the rocket in y-axis times speed
every second.
if(speed < maxSpeed)
speed += acceleration * Time.deltaTime;
We want to keep the rocket keep accelerating until it reaches the maxSpeed
, so what this code does is if speed
less than maxSpeed
ย we add acceleration
value per second until it reaches the maximum speed;
Debug.Log(speed);
ย with this code, we can trace the speed
in the console tab.
That's that, I told you this was a simple one!
![](https://digitalpress.fra1.cdn.digitaloceanspaces.com/e5q1bl6/2022/10/ezgif.com-gif-maker-1.gif)