Search Unity

Other VR Movement Not moving in wanted direction

Discussion in 'VR' started by AtlasT2022, Jun 20, 2022.

  1. AtlasT2022

    AtlasT2022

    Joined:
    Mar 12, 2022
    Posts:
    60
    I have a script for VR movement using the built in VR, but there's no errors, and still works, but it doesn't move in the right direction; It uses the new Input System.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class XRController : MonoBehaviour
    6. {
    7.     private Movement move;
    8.     private Movement.OnFootActions onFoot;
    9.     public GameObject Rig;
    10.     private Vector2 input;
    11.     private Vector3 Direction;
    12.     public float speed = 6.0f;
    13.     public GameObject Cam;
    14.     public CharacterController controller;
    15.     public float rot;
    16.  
    17.  
    18.     // Start is called before the first frame update
    19.     void Awake()
    20.     {
    21.       move = new Movement();
    22.       onFoot = move.OnFoot;
    23.         controller = Rig.GetComponent<CharacterController>();
    24.     }
    25.  
    26.     // Update is called once per frame
    27.     void Update()
    28.     {
    29.         rot = Cam.transform.localRotation.eulerAngles.y;
    30.         onFoot.Enable();
    31.         input = (onFoot.Movement.ReadValue<Vector2>());
    32.         Direction = Vector3.zero;
    33.         Direction.x = input.x;
    34.         Direction.z = input.y;
    35.         transform.eulerAngles = (new Vector3(0, rot, 0));
    36.         controller.Move(transform.TransformDirection(Direction) * speed * Time.deltaTime);
    37.     }
    38. }
    39.  
    Cam -- XR camera

    rot -- XR camera Y rotation

    Rig -- XRRig
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,059
    Is everything properly linked in the inspector?
    No errors or warnings?
    If you debug the onFoot movement, what does it say?
     
  3. AtlasT2022

    AtlasT2022

    Joined:
    Mar 12, 2022
    Posts:
    60
    Yep, all linked. But I've never tried debugging.
     
  4. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,059
    That's the first step when getting rid of bugs, debugging (;
     
  5. AtlasT2022

    AtlasT2022

    Joined:
    Mar 12, 2022
    Posts:
    60
    Idk how to debug inputs. I just found out how to read values last month xd
     
  6. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,059
    Put the reading value part in Debug.Log()
     
  7. AtlasT2022

    AtlasT2022

    Joined:
    Mar 12, 2022
    Posts:
    60
    Returns the expected Vector2 between -1.0 and +1.0.
    So how do I fix this? I tried
    Code (CSharp):
    1. Vector3.MoveTowards
    , but it wouldn't detect anything as shown in here:
    Code (CSharp):
    1. if (input.y >= 0.4)
    and
    Code (CSharp):
    1. if (input.y > 0.4)
    .
    The next question is why that ^ doesn't work