# Rotation for a movie clip...Keyboard Controls

**URL:** <https://forum.kirupa.com/t/rotation-for-a-movie-clip-keyboard-controls/64449>\
**Category:** flash\
**Created:** [September 16, 2004, 12:01pm UTC](https://forum.kirupa.com/t/rotation-for-a-movie-clip-keyboard-controls/64449 "2004-09-16T12:01:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![boolsu](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@boolsu](https://forum.kirupa.com/u/boolsu)\
**Post date:** [September 16, 2004, 12:01pm UTC](https://forum.kirupa.com/t/rotation-for-a-movie-clip-keyboard-controls/64449/1 "2004-09-16T12:01:08Z")

</div>

let me explain …  
By pressing and holding the (KeyBoard) left and right arrow keys should rotate the MC left and Right respectively  
Also by pressing the up arrow should move the MC in the direction it is pointing…  
Consider the movie clip as to be a space ship…  
Reply soon pleasse…  
Bala…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 16, 2004, 3:49pm UTC](https://forum.kirupa.com/t/rotation-for-a-movie-clip-keyboard-controls/64449/2 "2004-09-16T15:49:26Z")

</div>

for the left and right keys, you’d probably have something like this:  
on the movieclip that you would like to control:

```auto
onClipEvent(enterFrame) {
    if (Key.isDown(Key.LEFT)) {
        this._rotation -= 10; //rotate the ship 10 degrees to the left
    } else if (Key.isDown(Key.RIGHT)) {
        this._rotation += 10; //rotate the ship 10 degress to the right
    }
}

```

i’ll brb with the code to make it move in the direction it is facing… there is a file in the flash mx help directory that shows you exactly how to do it 🙂 i’ll post the code anyway… bbs  
hope this helps so far

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 16, 2004, 3:51pm UTC](https://forum.kirupa.com/t/rotation-for-a-movie-clip-keyboard-controls/64449/3 "2004-09-16T15:51:53Z")

</div>

this is the entire code, copy and pasted straight from the flash mx samples (i take no credit for this):

```auto
onClipEvent (load) {
	// declare and set initial variables
	thrust = 1;
	decay = .97;
	maxSpeed = 15;
}
onClipEvent (enterFrame) {
	// rotate right or left
	if (Key.isDown(Key.RIGHT)) {
		_rotation += 10;
	}
	if (Key.isDown(Key.LEFT)) {
		_rotation -= 10;
	}
	// 
	// 
	if (Key.isDown(Key.UP)) {
		// calculate speed and trajectory based on rotation
		xSpeed += thrust*Math.sin(_rotation*(Math.PI/180));
		ySpeed += thrust*Math.cos(_rotation*(Math.PI/180));
		flames._visible = 1;
	} else {
		// deccelerate when Up Arrow key is released
		xSpeed *= decay;
		ySpeed *= decay;
		flames._visible = 0;
	}
	// 
	// maintain speed limit
	speed = Math.sqrt((xSpeed*xSpeed)+(ySpeed*ySpeed));
	if (speed>maxSpeed) {
		xSpeed *= maxSpeed/speed;
		ySpeed *= maxSpeed/speed;
	}
	// 
	// move beetle based on calculations above
	_y -= ySpeed;
	_x += xSpeed;
	// 
	// loop to opposite side of the stage when the beetle travels off-screen
	if (_y<0) {
		_y = 232;
	}
	if (_y>232) {
		_y = 0;
	}
	if (_x<0) {
		_x = 465;
	}
	if (_x>465) {
		_x = 0;
	}
}

```

hope this helps you
