Search Unity

[Just Started] Rotation Issue

Discussion in 'Getting Started' started by Vunoo, Mar 16, 2018.

  1. Vunoo

    Vunoo

    Joined:
    Mar 14, 2018
    Posts:
    6
    Hey guys! I just started using Unity yesterday and I've been studying what I can do with its code and design-wise. Today I was trying to apply physics to my character following some random tutorials, videos and what not and ended up with a somewhat decent result. But my Rotation Y-axis wise is buggy to say the least. Could you give me a hand? I anexed 2 small videos showing my issue and the code for the camera controller.

    Here's 2 videos showing the issue:


    (the relevant one, sorry for not cutting the video..I'm that lazy :/)


    And here's the code for the camera:


    public class PlayerCamera : MonoBehaviour {
    Vector2 mouseLook; //total movement of the camera made
    Vector2 smoothV; //smoothness vector
    public float sensitivity = 3.0f;
    public float smoothing = 2.0f;
    GameObject player;
    // Use this for initialization
    void Start () {
    player = transform.parent.gameObject;
    //Cursor.lockState = CursorLockMode.Locked; //cursor stops being visible
    }
    // Update is called once per frame
    void Update () {
    var vec = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
    //var vec = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
    //vec = Vector2.Scale(vec, new Vector2(sensitivity * smoothing, sensitivity * smoothing));
    //smoothV.x = Mathf.Lerp(smoothV.x, vec.x, 1f);
    //smoothV.y = Mathf.Lerp(smoothV.y, vec.y, 1f);
    mouseLook += vec;
    mouseLook.y = Mathf.Clamp(mouseLook.y, -90f, 90f); //limit how much you can see up and right
    transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right); //y-axis mouse is used to rotate THE CAMERA up and down
    player.transform.localRotation = Quaternion.AngleAxis(mouseLook.x, player.transform.up); //x-axis mouse is used to rotate THE CHARACTER left and right
    }
    }



    I'd also like to ask one last thing if you don't mind. I have progamming background but still studying the correct manner to do things with the engine in terms of code. So far I've been following some random guides as well as the guide that the youtuber Brackeys made. Do you feel like there's something else that is worth to keep an eye at or invest a few bucks? (like the udemy courses or the one shared on this forum) I don't work yet so 20$ is 20$ :3


    Thank you so much for taking your time and helping me and all the newcomers out. I trully appreciate it! Wish you the best!
     
  2. Vunoo

    Vunoo

    Joined:
    Mar 14, 2018
    Posts:
    6
    Also, when you want to create a new Class to store relevant information (let's say the Class Car) do you follow the usual progamming principles or you stick all the data you need in controllers (like some of those prefab assets)
     
  3. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Depending on your programming experience, you could run through a few of the small game tutorials here on Unity's site, in the 'Learn' section. That should get you comfortable with Unity, in general.

    In the future, read this post for how to post code more nicely on the forums: https://forum.unity.com/threads/using-code-tags-properly.143875/
    I cannot read all of your post because it is cut off.

    Using what I'm a little more used to, this is a very basic piece of code that closely matches yours (I think)..
    Code (csharp):
    1. public class Test13 : MonoBehaviour
    2. {
    3.     Transform player;
    4.     float mouseLook;
    5.  
    6.     void Start()
    7.     {
    8.         player = transform.parent;
    9.     }
    10.  
    11.     void Update()
    12.     {
    13.         float mx = Input.GetAxis("Mouse X");
    14.         float my = Input.GetAxis("Mouse Y");
    15.  
    16.         mouseLook += my;
    17.         mouseLook = Mathf.Clamp(mouseLook, -45, 60);
    18.  
    19.         player.localRotation *= Quaternion.Euler(0, mx, 0);
    20.         transform.localRotation = Quaternion.Euler(-mouseLook, 0, 0);
    21.     }
    22. }
    As for courses, I hear good things about Udemy and for swords and shovels mostly good, too.
    I do believe it's an option, if you first spend some time getting used to Unity and getting a little bit done, first, before going forward. If you're still interested later, go for it.. :)
     
    JoeStrout likes this.
  4. Vunoo

    Vunoo

    Joined:
    Mar 14, 2018
    Posts:
    6
    First off, thank you very much for answering me. Although I used the /Code tag, I'll be more cautious in the future. I don't know why it didn't end up in that format though, but since the letters were quite different I thought it had applied :/ Sorry about that, mate.

    I just graduated in computer engineering, while I am nowhere near a professional, I think I'm pretty decent at it. But It'll still take me some time to study Unity's coding Arquitecture. Hopefully not much though! I hope I'll be capable of doing something basic but decent enough by the end of this month. We'll see.

    I'll take your suggestion and take a look at those game tutorials, so thank you for that and for resolving my issue! See you around Methos!
     
  5. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    It is because of the silliest button there that does code, with ICODE.. sadly not very good tags (not your fault, I see many people using them, lately lol)

    In any event, you should be good since you have some experience with programming. You won't struggle to understand the programming part, even in simple tutorials, but it'll expose you to using Unity and I think that'll help you a lot.

    Anyways, welcome & have fun :)