x


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?

more ▼

asked Jan 03, 2010 at 05:36 PM

James gravatar image

James
60 8 7 14

(comments are locked)
10|3000 characters needed characters left

2 answers: sort oldest

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.

more ▼

answered Jan 03, 2010 at 06:06 PM

TowerOfBricks gravatar image

TowerOfBricks
3.9k 50 50 80

Didn't realize I could accept an answer and comment! The AddRelativeForce was exactly what I was looking for. Thank you!

Jan 05, 2010 at 11:28 PM James
(comments are locked)
10|3000 characters needed characters left

www.unitytutorials.com has three tutorials (15$ each) about an Asteriods game. Here is a link.

more ▼

answered Jan 04, 2010 at 02:20 PM

TriplePAF gravatar image

TriplePAF
98 18 17 35

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x9278
x50

asked: Jan 03, 2010 at 05:36 PM

Seen: 2100 times

Last Updated: Jan 03, 2010 at 05:36 PM