- Home /
How can I create a control scheme like Asteroids?
Hello, I am a game designer who is trying to learn some scripting. However, I have no idea where to begin on this prototype of mine. You see, I have this rocket sitting in my scene which I want to control with a system similar to Asteriods. You know, rotate and thrust. But I just don't have any clue where to start. I understand the concepts behind programming languages, but I lack the experience to do this without some guidance.
Here is some information about the game, Liftoff:
The goal is to blast off from a planet's surface and escape its gravity well. It is played on vertical scrolling levels filled with obstacles. Think Asteroids with gravity on rails.
My main concern is getting the rocket manipulated by the keyboard the way I want. I'll worry about the rest of the game once I get the controls feeling right. Can anyone help me?
Answer by TowerOfBricks · Jan 03, 2010 at 06:06 PM
Take a look at the rigidbody class
It is the component which controls all the physics stuff so you don't have to worry about it (very much).
And take a look at the Input Class which is the class from where you can get key presses and such stuff.
Now, an example:
If you want to move your rocket forward/backwards when you press the up/down (or w/s) keys you can do it like this:
var speed : float = 1;
//Run the code in fixed update to ensure stable physicsx function FixedUpdate () { //Get the input value, you can change the input keys in the Input Manager var vert : float = Input.GetAxis ("Vertical");
//Add a force relative to the objects rotation (not the world)
rigidbody.AddRelativeForce (Vector3.forward * speed);
}
Hope it helps.
Didn't realize I could accept an answer and comment! The AddRelativeForce was exactly what I was looking for. Thank you!
Answer by TriplePAF · Jan 04, 2010 at 02:20 PM
www.unitytutorials.com has three tutorials (15$ each) about an Asteriods game. Here is a link.
Your answer
![](https://koobas.hobune.stream/wayback/20220613195554im_/https://answers.unity.com/themes/thub/images/avi.jpg)