Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object Instantiated inside GridObjectCollection of ScrollingObjectCollection with opposite rotation #11786

Closed
tranquanglam123 opened this issue Oct 5, 2023 · 1 comment
Labels

Comments

@tranquanglam123
Copy link

Describe the bug

I created a ScrollingObjectCollection name LeftScroll, it is a child of a gameobject name QSB which has SolverHandler to track the user's head.
image
LeftScroll has a GridObjectCollection inside the container, I scripted for the item to spawn inside the GridObjectCollection with the rotation of (0,0,0).
image
But in run time, whenever i turn around, the QSB's rotation changes so it can follow me, then the item spawned with the opposite rotation of the QSB ( for instance QSB (-5,30,0) -> item (5,-30,0)
image

##Steps to reproduce the behavior:

  1. Create an object with solver handle to track the head
  2. Create a child with scrollingobjectcollection -> gridobjectcollection inside container
  3. Attached this script section inside the parent object and assign any object to be the item
    "for (int i = 0; i < ItemsPerPage; i++)
    {
    ItemBox tmpBox = Instantiate(SpawnItemBox);
    tmpBox.name = Manager.dataMachine[Manager.selectMachine].objectData[i].Name;
    tmpBox.SetIconName(tmpBox.name);
    tmpBox.transform.SetParent(ItemSlots);
    tmpBox.SetQuadIcon(Manager.dataMachine[Manager.selectMachine].objectData[i].smallicon);
    tmpBox.index = Manager.dataMachine[Manager.selectMachine].objectData[i].ID;
    Debug.Log("item id:" + tmpBox.index);
    tmpBox.transform.rotation = Quaternion.Euler(Vector3.zero);
    tmpBox.transform.localScale = new Vector3(1, 1, 1);
    ItemBoxes.Add(tmpBox);
    }
    StartCoroutine(InvokeUpdateCollection(griditem,scrollitem));
    Debug.Log("Grid Updated");"}
    private IEnumerator InvokeUpdateCollection(GridObjectCollection temp,ScrollingObjectCollection temp2)
    {
    yield return null;
    temp.UpdateCollection();
    yield return null;
    temp2.UpdateContent();
    }"
  4. Run and see error

Expected behavior

Items spawned with rotation of (0,0,0) despite whatever direction the user's head.

Your setup (please complete the following information)

  • Unity Version [2021.3.16f1]
  • MRTK Version 2.8.3

Target platform (please complete the following information)

  • Meta Quest 2
@tranquanglam123
Copy link
Author

The solution is actually simple, instead of using the prop "rotation", just use the "localRotation"
image

Explaination
"rotation" is the absolute rotation of the object in the scene while the "localRotation" is relative to its parent, so set it to 0,0,0, the component should be aligned with its parent.

@AMollis AMollis closed this as not planned Won't fix, can't repro, duplicate, stale Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants