can anyone please write a script that will allow my character to rotate when either a or d is pressed ive tried tons of other scripts but none of them work please can anyone help?
By default, the A and D keys (along with <- & -> ) are mapped to the Horizontal Axis input.
So you can also use:
var degs : float = 30; // degrees per second
var rot :float; // we'll take these out so we aren't defining every frame
function Update(){
rot = Input.GetAxis("Horizontal"); // returns a value between -1 and +1
transform.Rotate(0, rot * degs * Time.deltaTime, 0);
}
This should rotate the object in the direction of your horizontal control (left and right or A and D) on the Y axis, by degs degrees per second.
There ya go...
var target:Transform;
var isRotate = false;
var rotationSpeed:float = 100;
function Update(){
if ( Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D) )
isRotate = true;
if (isRotate)
target.Rotate(Vector3.forward * Time.deltaTime * rotationSpeed );
}
Please double check for bugz cause I havent the chance to check it yet