Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[CLOSED] Player Controller Rotation

Discussion in 'Scripting' started by chips, Dec 20, 2007.

  1. chips

    chips

    Joined:
    Nov 30, 2007
    Posts:
    138
    Hi! I'm having some problems trying to build a controller that rotates acording with the arrow keys. Someting like the caracter Link, in the game A link to the past, when the player presses left, the the caracter switch to the left and runs to the left. The same should work to the diagonals.
    The pre fabs creates a player that rolls to the sides but I can't "see in numbers ou degrees" how much it has rolled...

    I've tried to use the World.rotate, but I'm having only buggs. :(

    Can any one gimme a tip about what should I do?

    TXS
     
  2. pete

    pete

    Joined:
    Jul 21, 2005
    Posts:
    1,647
  3. chips

    chips

    Joined:
    Nov 30, 2007
    Posts:
    138
    I'm still trying to build a player witch rotates acording with the arrow keys. I've already made this:
    Code (csharp):
    1.  
    2.  
    3. var angle : float = 0;
    4.  
    5. var angledif : float = 0;
    6.  
    7. var PlayerSpeed : float;
    8.  
    9. function Update () {
    10.         if (Input.GetKey("left")  Input.GetKey("up")){
    11.             angle=45;
    12.             transform.Translate(0,0,PlayerSpeed);
    13.         }else{
    14.             if(Input.GetKey("left")  Input.GetKey("down")){
    15.                 transform.Translate(Vector3(0,0,PlayerSpeed));
    16.                 angle=-45;
    17.             }else{
    18.  
    19.                 if(Input.GetKey("right")  Input.GetKey("up")){
    20.                     transform.Translate(Vector3(0,0,PlayerSpeed));
    21.                     angle=135; 
    22.                 }else{
    23.  
    24.                     if(Input.GetKey("right")  Input.GetKey("down")){
    25.                         transform.Translate(Vector3(0,0,PlayerSpeed));
    26.                         angle=-135;
    27.                     }else{ 
    28.                         if (Input.GetKey("left")){
    29.                             //UpdatePosition(0 , 1 , PlayerSpeed );
    30.                             transform.Translate(Vector3(0,0,PlayerSpeed));
    31.                             angle=0;
    32.                         }else{
    33.                             if (Input.GetKey("up")){
    34.                                 //UpdatePosition(1 , 0 , PlayerSpeed );
    35.                                 transform.Translate(Vector3(0,0,PlayerSpeed));
    36.                                 angle=90;
    37.                             }else{
    38.  
    39.                                 if (Input.GetKey("down")){
    40.                                     //UpdatePosition(-1 , 0 , PlayerSpeed );   
    41.                                     transform.Translate(Vector3(0,0,PlayerSpeed));
    42.                                     angle=-90;
    43.                                 }else{
    44.  
    45.                                     if (Input.GetKey("right")){
    46.                                         //UpdatePosition(0 , -1 , PlayerSpeed );   
    47.                                         transform.Translate(Vector3(0,0,PlayerSpeed));
    48.                                         angle=180;
    49.                                     }
    50.                                 }
    51.                             }
    52.                         }
    53.                     }
    54.                 }
    55.             }
    56.         }
    57.  
    But I need a smoothness between each arrow pressed.

    I've tryed something like that:
    Code (csharp):
    1.  
    2.     angledif = transform.eulerAngles.y - angle;
    3.     print("Angular Diference" + Mathf.Abs(angledif));
    4.  
    5.     print("ActualRotation"+transform.eulerAngles.y);
    6.     transform.eulerAngles.y=angle;
    7.  
    8.  
    But the angular difference gimme sometimes two results one after an other...
    Can anyone gimme a hand with that?
    TXS!
     
  4. spawrks

    spawrks

    Joined:
    Nov 16, 2007
    Posts:
    89
    Usually I've set rotations directory through the Vector3 value, like so:

    transform.eulerAngles = Vector3(0,270,0);

    But I can't quite understand from your code what bug you might be getting.

    The best information I can give you is to take a look at the following controller example. I'm not sure what bugs you're running into, but this controller is available somewhere in the animation examples, and does I think what you're asking.
     

    Attached Files:

  5. Omar Rojo

    Omar Rojo

    Joined:
    Jan 4, 2007
    Posts:
    494
    I did something like this a time ago, i dont know if this is what you want but take a look and if it is, i can show you my character controller code :D

    It moves relative to the camera and i added an always-advance movement because i was too lazy to do an idle animation :D

    .org
     

    Attached Files:

  6. chips

    chips

    Joined:
    Nov 30, 2007
    Posts:
    138
    Thanks 4 all your help!!!

    []s Chips