Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Upside-down issue with teleport

Discussion in 'Scripting' started by Galbert-IT, Apr 11, 2020.

  1. Galbert-IT

    Galbert-IT

    Joined:
    Mar 8, 2020
    Posts:
    7
    Hello everybody, I'm experiencing a frustrating issue with teleport: very often, the target rotation is not aligned with the ground, and after teleporting I find myself in really weird positions, like lying horizontally or close to being upside-down... I don't know the cause but it happens pretty soon after some teleports every time I run my VR game.
    Here is a little screenshot to help you understand what I mean:

    The arrow is not parallel to the ground, it is sort-of pointing downwards

    Teleport.PNG

    Here is the setup of my teleport-dedicated game object:

    I Config1.PNG
    Config2.PNG
    In reality, the two "...during post teleport" checkboxes are enabled, I took the picture when I turned them off just to see if this could help (it didn't).

    Do you have any hints that may help? How can I freeze the X and Z components of the teleport destination rotation in order to avoid such behaviour? It must rotate on the Y axis only, to determine where I look after teleporting, but still standing (not crawling or whatever)!

    Thank you,
    Fabio
     
  2. Alvarezmd90

    Alvarezmd90

    Joined:
    Jul 21, 2016
    Posts:
    149
    The inspector view snaps you posted don't have anything to do with your issue. I kinda wanna see the code related to the teleporter snapping into the place of the raycast and how the normal calculation is done.
    You can zero out rotation by multiplying one axis by 0.
     
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    Agreed, I'd like to see some of the code. We have no idea what your various component scripts actually do.
     
  4. Galbert-IT

    Galbert-IT

    Joined:
    Mar 8, 2020
    Posts:
    7
    Hi there, thank you for reaching out!

    I assume the function below may be the correct one to act on! Do you agree?


    protected override void UpdateTeleportDestination()
    {
    float magnitude;
    Vector2 direction;
    if (Thumbstick == OVRInput.Controller.Touch)
    {
    Vector2 leftDir = OVRInput.Get(OVRInput.RawAxis2D.LThumbstick);
    Vector2 rightDir = OVRInput.Get(OVRInput.RawAxis2D.RThumbstick);
    float leftMag = leftDir.magnitude;
    float rightMag = rightDir.magnitude;
    if (leftMag > rightMag)
    {
    magnitude = leftMag;
    direction = leftDir;
    }
    else
    {
    magnitude = rightMag;
    direction = rightDir;
    }
    }
    else
    {
    if(Thumbstick == OVRInput.Controller.LTouch) direction = OVRInput.Get(OVRInput.RawAxis2D.LThumbstick);
    else direction = OVRInput.Get(OVRInput.RawAxis2D.RThumbstick);
    magnitude = direction.magnitude;
    }

    if (!AimData.TargetValid)
    {
    _lastValidDirection = new Vector2();
    }

    if (magnitude < RotateStickThreshold)
    {
    direction = _lastValidDirection;
    magnitude = direction.magnitude;

    if (magnitude < RotateStickThreshold)
    {
    _initialRotation = LocomotionTeleport.GetHeadRotationY();
    direction.x = 0;
    direction.y = 1;
    }
    }
    else
    {
    _lastValidDirection = direction;
    }

    var tracking = LocomotionTeleport.LocomotionController.CameraRig.trackingSpace.rotation;

    if (magnitude > RotateStickThreshold)
    {
    direction /= magnitude; // normalize the vector
    var rot = _initialRotation * Quaternion.LookRotation(new Vector3(direction.x, 0, direction.y), Vector3.up);
    _currentRotation = tracking * rot;
    }
    else
    {
    _currentRotation = tracking * LocomotionTeleport.GetHeadRotationY();
    }

    LocomotionTeleport.OnUpdateTeleportDestination(AimData.TargetValid, AimData.Destination, _currentRotation, GetLandingOrientation(OrientationMode, _currentRotation));
    }
     
  5. TimZech

    TimZech

    Joined:
    Apr 5, 2016
    Posts:
    4
    Hi Galbert,

    today I ran into the same problem. Weird thing for me is, that it only appears in a specific scene. Did you manage to fix the problem?