Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1
    Join Date
    Mar 2011
    Location
    Rome, Italy
    Posts
    16

    simple turn player

    Hi guys,
    i try to learn unity, someone can help me to turn (only turn) the player left and right.
    I want use the keys "A" and "D" for turn the player, and the keys "Q" and "E" for strafe.

    Someone can help me.

    tks a lot.

    (tutorial 3rd person)

  2. #2
    Join Date
    Jan 2011
    Location
    Blackpool, UK
    Posts
    853
    This should help you on your way: http://unity3d.com/support/documenta...rm.Rotate.html

    Have a play around with the logic, maybe multiply the rotation by (input.getkey("A")-input.getkey("D")).
    Last edited by darkmobius; 06-13-2011 at 02:58 PM.

  3. #3
    Join Date
    Sep 2008
    Location
    Salisbury, UK
    Posts
    2,812
    Alternatively, you could adapt the TP Camera system from Lee's videos to check A & D keys rather than the mouse position - strafing is covered there too.

    I found
    my current avatar on google, so props to THIS GUY who created the original...

  4. #4
    Join Date
    Mar 2011
    Location
    Rome, Italy
    Posts
    16
    Ok, tks for help...now next prob
    in the TP_Controller i put:
    Code:
    if (Input.GetKeyDown(KeyCode.A))
            {
                RotateLeft();
            }
            if (Input.GetKeyDown(KeyCode.D))
            {
                RotateRight();
            }
    
        void RotateLeft()
        {
            TP_Motor.Instance.TurnRight();
        }
    
        void RotateRight()
        {
            TP_Motor.Instance.TurnLeft();
        }
    and in the TP_Motor
    Code:
    public void TurnLeft()
        {
            transform.rotation = Quaternion.Euler(transform.eulerAngles.x, transform.eulerAngles.y + 10, transform.eulerAngles.z);
        }
    
        public void TurnRight()
        {
            transform.rotation = Quaternion.Euler(transform.eulerAngles.x, transform.eulerAngles.y - 10, transform.eulerAngles.z);
        }
    +-10 is just for trying
    but how can "understand" that the player dont finish to rotate the player (i dont wanna press 36 times the key for rotate completly the animation).

    I lose something and i dont understand.
    Last edited by fatgav; 06-13-2011 at 04:22 PM.

  5. #5
    Join Date
    Sep 2008
    Location
    Salisbury, UK
    Posts
    2,812
    Please use code tags - it makes it far easier for people to read your code. I've put them into your first post in case you're unclear on how to do this.

    To answer your question; use GetKey(KeyCode.blah) instead of GetKeyDown(KeyCode.blah) in TP_Controller.

    I found
    my current avatar on google, so props to THIS GUY who created the original...

  6. #6
    Join Date
    Jan 2011
    Location
    Blackpool, UK
    Posts
    853
    You may want to use GetButton and set "A" and "D" in the Input Settings. That way you're not hard coding the key choices.

  7. #7
    Join Date
    Mar 2011
    Location
    Rome, Italy
    Posts
    16
    right, sorry, i use tags, i promise.

    change getkeydown with getkey...sooooo easyyyyyyyyyyyyyyyyyyyyyyyyyyyy

    tks a lot!!!

  8. #8
    Join Date
    Jan 2011
    Location
    Blackpool, UK
    Posts
    853
    Quote Originally Posted by Gothrek View Post
    right, sorry, i use tags, i promise.

    change getkeydown with getkey...sooooo easyyyyyyyyyyyyyyyyyyyyyyyyyyyy

    tks a lot!!!
    Sometimes it only takes one small change. Besides there are always many ways of achieving the same thing. I tend to learn a lot by trying things and making mistakes.

  9. #9
    Join Date
    Sep 2008
    Location
    Salisbury, UK
    Posts
    2,812
    I still have to stop and think every time with those two - I know the difference but I still do a mental double-take.

    I found
    my current avatar on google, so props to THIS GUY who created the original...

  10. #10
    Join Date
    Jan 2011
    Location
    Blackpool, UK
    Posts
    853
    Quote Originally Posted by fatgav View Post
    I still have to stop and think every time with those two - I know the difference but I still do a mental double-take.
    Me too, the number of times I have to "reinvent the wheel" is embarrassing. I'm definitely going to start building a library of scripts and assets.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •