I have created a player character controller. It rotates first time good but not after rotate to its original position before rotation. I am sharing code with you so any one can help me, How can I rotate character controller to 60 on Z-axis and again back to 0 degree on Z-axis?

void Update()
    var inputDirection = inputDetector.DetectInputDirection();

    if (Input.GetKeyDown (KeyCode.Space)) {
        moveDirection.y = JumpSpeed;
        anim.SetBool ("RunToJump", true);
    } else {
        anim.SetBool ("RunToJump", false);

    if (Input.GetKey (KeyCode.S) && controller.isGrounded) {                        
        anim.SetBool ("RunToSlip", true);
        controller.transform.Rotate (0, 0, 60);
        Invoke ("StopSlidding", 0.1f);
   void StopSlidding(){
   anim.setbool("RunToSlip", false);

First controller.transform.Rotate(0,0,60); works fine but second time I invoke StopSlidding method controller.transform.Rotate(0,0,60); It doesn't work. So my player character controller remains same on Z-axis 60 degree. I want to rotate it again to Z-axis 0 degree. So Any one can help me on this problem? My player starts moving with game scene start so there are no matter about moving player. I am using Controller.Move(); to move my player.


Because you are telling it to rotate by 60 on the Z axis, and then the 2nd time you are telling it to rotate by 0 (no change).

Either change your 2nd to (0, 0, -60) or use transform.rotation instead of transform.Rotate()

  • \$\begingroup\$ Yaah man, thanks i forget that or i can't focus on that. thanks for help me \$\endgroup\$ – hardwork Aug 18 '16 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.