Search Unity

Right Joystick rotation

Discussion in 'Editor & General Support' started by Mr_AgentFox, Jul 15, 2019.

  1. Mr_AgentFox

    Mr_AgentFox

    Joined:
    Jun 23, 2019
    Posts:
    57
    Just watched Brackeys new Controler Input video and I have my own code to move and rotate my camera (his didn't work for me). I have the movement worked out but I want to know what to put in the quotes for the right joystick input. it says
    "yaw += speedH * Input.GetAxis("Mouse X");"
    "yaw -= speedV * Input.GetAxis("Mouse Y");" I just want to know what to put in the quotes where the Mouse X / Mouse Y is. any suggestions?

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.InputSystem;
    3.  
    4. public class Controler : MonoBehaviour
    5. {
    6.  
    7.     public float runSpeed = 5f;
    8.     public float shiftSpeed = 10f;
    9.  
    10.     public float speedH = 2f;
    11.     public float speedV = 2f;
    12.  
    13.     private float yaw = 0.0f;
    14.     private float pitch = 0.0f;
    15.  
    16.     PlayerControls controls;
    17.  
    18.     Vector2 move;
    19.     Vector2 rotate;
    20.  
    21.     void Awake()
    22.     {
    23.         controls = new PlayerControls();
    24.  
    25.         controls.Gameplay.Move.performed += ctx => move = ctx.ReadValue<Vector2>();
    26.         controls.Gameplay.Move.canceled += ctx => move = Vector2.zero;
    27.  
    28.         controls.Gameplay.Rotate.performed += ctx => rotate = ctx.ReadValue<Vector2>();
    29.         controls.Gameplay.Rotate.canceled += ctx => rotate = Vector2.zero;
    30.     }
    31.  
    32.     void OnEnable()
    33.     {
    34.         controls.Gameplay.Enable();
    35.     }
    36.  
    37.     void Update()
    38.     {
    39.         transform.Translate(new Vector3(runSpeed * Input.GetAxis("Horizontal") * Time.deltaTime, 0f, runSpeed * Input.GetAxis("Vertical") * Time.deltaTime), Space.Self);
    40.  
    41.         yaw += speedH * Input.GetAxis("Mouse X"); // Joystick X?
    42.         pitch -= speedV * Input.GetAxis("Mouse Y"); // Joystick Y?
    43.  
    44.         transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
    45.     }
    46.  
    47.     void OnDisable()
    48.     {
    49.         controls.Gameplay.Disable();
    50.     }
    51. }
    52.  
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    735
    You can't mix the two different Input systems, and unless you're just testing the new system out, you should stick with the current system as the new one is still in preview.
    I like Brackey's videos, but he does seem to have a habit of telling his viewers that preview features are released (for some reason), like he did with the video you're referring to here.

    Though, what you have here for rotation should work. Have you tried using
    transform.Rotate()
    instead of
    transform.eulerAngles
    ?
     
  3. Mr_AgentFox

    Mr_AgentFox

    Joined:
    Jun 23, 2019
    Posts:
    57
    on this line? "transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);" I tried it and got a red line...
     
  4. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    735
    What does the error message say when you try that?
     
  5. Mr_AgentFox

    Mr_AgentFox

    Joined:
    Jun 23, 2019
    Posts:
    57
    error CS1501: No overload for method ‘rotate’ takes 0 arguments
     
  6. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    735
    Well, yeah, it's the same as
    transform.Translate()
    - you need to supply a Vector3/2 value. Use the
    rotate
    vector that you have declared.
    Code (CSharp):
    1. transform.Rotate(rotate);
    Edit: Actually, looking at how you've done your
    transform.Translate()
    code, you're not making use of the new Input system, you're still using the old system.
    You have a
    move
    vector that's being assigned, but never used.
    Simply writing this should work:
    Code (CSharp):
    1. transform.Translate(move);
    The new Input system means to eliminate the use of
    Input.GetButton...
    functions.
     
    Last edited: Jul 15, 2019
  7. Mr_AgentFox

    Mr_AgentFox

    Joined:
    Jun 23, 2019
    Posts:
    57
    Sorry for all the one corrections. But where do I place the line of code you have given me, and I need to fix rotation. I can move just fine but I cannot rotate with the right stick.
     
  8. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    735
    Replace this...
    Code (CSharp):
    1. transform.Translate(new Vector3(runSpeed * Input.GetAxis("Horizontal") * Time.deltaTime, 0f, runSpeed * Input.GetAxis("Vertical") * Time.deltaTime), Space.Self);
    ...With this:
    Code (CSharp):
    1. transform.Translate(move * runSpeed * Time.deltaTime);
    And this...
    Code (CSharp):
    1. transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
    ...With this:
    Code (CSharp):
    1. transform.Rotate(rotate * Time.deltaTime);
    When using the new Input system, there should be no trace of any
    Input.GetButton...
    functions, as those are part of the old system, which again, should still be used unless you're just testing out the new system here.
     
  9. Mr_AgentFox

    Mr_AgentFox

    Joined:
    Jun 23, 2019
    Posts:
    57
    Am I supposed to be able to move and rotate?
     
  10. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    735
    Yes. If you still cannot get it working, you may want to re-watch the tutorial video.
     
  11. Mr_AgentFox

    Mr_AgentFox

    Joined:
    Jun 23, 2019
    Posts:
    57

    Sure! Thanks for the help!
     
  12. Mr_AgentFox

    Mr_AgentFox

    Joined:
    Jun 23, 2019
    Posts:
    57
    I have rewatched the tutorial and his controls still don't work for me. IDK why...