- Home /
How would I do Asteroids style moving?
Hi, I'm working on an Asteroids game, and I can't figure out how I would do Asteroids style moving. I'm going for the classic Asteroids effect where, after speeding up, you don't slow down until you press the opposite key. How would I do that?
Thanks, Elliot B.
Answer by Eric5h5 · Jun 05, 2010 at 04:56 PM
Use the physics engine, where you have an object with a rigidbody and this script:
var rotateSpeed = 360.0; var thrustSpeed = 25.0;
function FixedUpdate() { transform.Rotate (Vector3.up (Input.GetAxis("Horizontal") rotateSpeed * Time.deltaTime) );
if (Input.GetButton("Thrust") ) { rigidbody.AddRelativeForce (Vector3.forward thrustSpeed Time.deltaTime); } }
You can use drag to limit speed, because in Asteroids you do actually slow down over time. If you don't want that, then you have to limit speed some other way (check rigidbody.velocity maybe).
Answer by Tobias · Jun 05, 2010 at 01:36 PM
You should make a var speed.
While you hold down the movment key you should increase this var (Until max speed is reached).
Now do a loop where you transform your charakter + speed.
And ofcourse when you press the oposite key decrease the var speed Hope you understand what I mean.
Answer by Potapczuk · Jun 05, 2010 at 07:16 PM
Check this little Asteroid game that i made with Unity for study purposes:
http://www.diegoliveira.com.br/asteroids/index.htm
It may help with some ideas.
Btw, it is not completed.