- Home /
rotation using the left arrow of the keyboard
i have a script(not written by me) to move a character forward(right arrow) and backward(left arrow) with the jump action(up arrow)...but i need my character to rotate when i press the left arrow and to also use the back arrow to move when rotated...i need answers pls...
var speed : float = 6.0;
var speed2 : float=10;
var jumpSpeed : float = 8.0;
var jumpSpeed2 : float = 18.0;
var gravity : float = 20.0;
private var moveDirection : Vector3 = Vector3.zero;
var pop : AudioClip;
// var puzzle : AudioClip;
function Update() {
if(Input.GetKeyDown(KeyCode.RightArrow)){
animation.Play("TIMI ANIMATION");
//audio.PlayOneShot(puzzle);
}
if(Input.GetKeyDown(KeyCode.LeftArrow)){
transform.Rotate(Vector3(0.0, 180.0, 0.0));
}
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded) {
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = Vector3(0, 0, Input.GetAxis("Horizontal"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
//audio.PlayOneShot(puzzle);
if(Input.GetKey(KeyCode.UpArrow)){
moveDirection.y = jumpSpeed;
audio.PlayOneShot(pop);
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}
function HighJump(){
var controller : CharacterController = GetComponent(CharacterController);
/* moveDirection = Vector3(0, 0,
1);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed2;
*/
moveDirection.y = jumpSpeed2;
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}
Comment
Answer by Commander5518 · Mar 14, 2014 at 01:43 PM
to rotate it would be
function Update(){
if(Input.GetKeyDown("right arrow")){
rigidbody.AddRelativeTorque(Vector3.right);
}
}