Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Rotation Not Working for GameObject Collections

Discussion in 'VR' started by spinteractive, Aug 21, 2016.

  1. spinteractive

    spinteractive

    Joined:
    Dec 19, 2015
    Posts:
    75
    Hello,
    I am using a very simple script to rotate a object in the Update() on Hololens using Voice command.

    This script works on a mesh/object directly, but does not work on a collection of meshes/objects.

    I create an empty GameObject and insert prefabs and 3D meshes in this GameObject (So it's the parent) . I am trying to rotate the GameObject - the parent. It doesn't.

    My Voice command to 'spin object' works only directly on a mesh, not a collection of meshes.
    Any ideas?

    ---SPEECH MANGER--
    keywords.Add("Spin Diamond", () =>
    {
    var focusObject = GazeGestureManager.Instance.FocusedObject;
    if (focusObject != null)
    {
    // Call the OnDrop method on just the focused object.
    focusObject.SendMessage("StartRotate");
    }
    });

    --SPIN OBJECT--
    // Called by SpeechManager when the user says the "Spin Object" command
    void StartRotate()
    {
    rotate = true;
    }
    // Called by SpeechManager when the user says the "Stop Spinning" command
    void StopRotate()
    {
    rotate = false;
    }
    // Update is called once per frame
    void Update () {
    if (rotate)
    {
    // Rotate Object
    this.transform.parent.Rotate(Vector3.up, Time.deltaTime * 10);
    }
    }
     
    Last edited: Aug 21, 2016
  2. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    558
    Hello,

    The other thing you need to do is to setup a Ray-cast from your camera so you can hit the collider of the object and spin it.

    Here is an example

    RaycastHit raycastHit;
    var cameraTransform = Camera.main.transform;

    if (Physics.Raycast(cameraTransform.position, cameraTransform.forward, out raycastHit))
    {
    //Do somehting here with the object you hit
    //SetCurrentCollider(raycastHit.collider);
    }
    else
    {
    SetCurrentCollider(null);
    }

    Thank you,
    Wesley
     
  3. spinteractive

    spinteractive

    Joined:
    Dec 19, 2015
    Posts:
    75
    Hi Wesley,
    Yes I saw this in the examples in the Holographic Academy. I will implement. Thank you!!
     
  4. spinteractive

    spinteractive

    Joined:
    Dec 19, 2015
    Posts:
    75
    Hi Wesley,
    It still doesn't spin my collections of objects - only the ones with direct mesh. I did like you mentioned. I also looked over the API reference. I want the object to spin continuously even when not gazing at it.
    Thanks for your help.

    using UnityEngine;
    using System.Collections;

    public class SpinObject : MonoBehaviour {

    bool rotate;

    // Use this for initialization
    void Start () {

    }

    // Called by SpeechManager when the user says the "Spin Object" command
    void StartRotate()
    {

    rotate = true;
    }

    // Called by SpeechManager when the user says the "Stop Spinning" command
    void StopRotate()
    {
    rotate = false;
    }

    // Update is called once per frame
    void Update () {

    if (rotate)
    {
    RaycastHit raycastHit;
    var cameraTransform = Camera.main.transform;

    if (Physics.Raycast(cameraTransform.position, cameraTransform.forward, out raycastHit))
    {
    // Rotate Object
    this.transform.Rotate(Vector3.up, Time.deltaTime * 50);
    }
    }
    }
    }
     
  5. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    558
    It looks like the issue is that you are rotating the object only when you are looking at it because you have it in the if(Raycast) loop.

    I think what you want to do is ray-cast out and get the collider from the hit info, then outside of the loop check use if(rotate) loop and use the collider to spin the game object.

    Here is an example of what could work.

    using UnityEngine;
    using System.Collections;

    public class SpinObject : MonoBehaviour {

    bool rotate = false;
    Collider Target;

    // Use this for initialization
    void Start () {

    }

    // Called by SpeechManager when the user says the "Spin Object" command
    void StartRotate()
    {

    rotate = true;
    }

    // Called by SpeechManager when the user says the "Stop Spinning" command
    void StopRotate()
    {
    rotate = false;
    }

    // Update is called once per frame
    void Update () {

    RaycastHit raycastHit;
    var cameraTransform = Camera.main.transform;

    if (Physics.Raycast(cameraTransform.position, cameraTransform.forward, out raycastHit))
    {
    //Store the collider
    m_SpinTarget = raycastHit.collider;
    }

    if (rotate)
    {
    m_SpinTarget.gameObject.transform.Rotate(Vector3.up,Time.deltaTime * 50);
    }
    }
    }
     
  6. spinteractive

    spinteractive

    Joined:
    Dec 19, 2015
    Posts:
    75
    Hi Wesley,
    Thanks for the response. I switched the script around. Now I'm using click gesture to spin the objects and they all spin at the collection level.

    My voice commands do not work at the collection level. Only at the mesh level. Basically, same problem as before. This demonstrates it's not an issue with ray-casting inside or outside the scope as you posted.

    I can still only activate voice command on the mesh. I'm confused.

    Here's the script.. any ideas

    using UnityEngine;

    public class DiamondCommands : MonoBehaviour
    {
    //spin
    bool spinObject = false;
    bool moveObject = false;

    AudioSource audioSource = null;
    AudioClip tapSound = null;

    void Start()
    {
    // Add an AudioSource component and set up some defaults
    audioSource = gameObject.AddComponent<AudioSource>();
    audioSource.playOnAwake = false;
    audioSource.spatialize = true;
    audioSource.spatialBlend = 1.0f;
    audioSource.dopplerLevel = 0.0f;
    audioSource.rolloffMode = AudioRolloffMode.Custom;

    // Load the Sphere sounds from the Resources folder
    tapSound = Resources.Load<AudioClip>("Impact");
    }

    // Called by GazeGestureManager when the user performs a Select gesture
    void OnSelect()
    {
    // On each Select gesture, toggle whether the user is in placing mode.
    spinObject = !spinObject;

    audioSource.clip = tapSound;
    audioSource.Play();
    }

    // Called by SpeechManager when the user says the "Move Diamond" command
    void Move()
    {
    moveObject = true;
    SpatialMapping.Instance.DrawVisualMeshes = true;
    audioSource.clip = tapSound;
    audioSource.Play();
    }

    // Called by SpeechManager when the user says the "Place Diamond" command
    void Place()
    {
    moveObject = false;
    SpatialMapping.Instance.DrawVisualMeshes = false;
    audioSource.clip = tapSound;
    audioSource.Play();
    }


    // Update is called once per frame
    void Update()
    {

    // Do a raycast into the world that will only hit the Spatial Mapping mesh.
    var headPosition = Camera.main.transform.position;
    var gazeDirection = Camera.main.transform.forward;
    RaycastHit hitInfo;

    if (moveObject)
    {
    if (Physics.Raycast(headPosition, gazeDirection, out hitInfo, 30.0f, SpatialMapping.PhysicsRaycastMask))
    // Move this object's parent object to
    // where the raycast hit the Spatial Mapping mesh.
    this.transform.parent.position = hitInfo.point;

    // Rotate this object's parent object to face the user.
    Quaternion toQuat = Camera.main.transform.localRotation;
    toQuat.x = 0;
    toQuat.z = 0;
    this.transform.parent.rotation = toQuat;
    }

    if (spinObject)
    {
    if (Physics.Raycast(headPosition, gazeDirection, out hitInfo))
    // Rotate Object
    this.transform.parent.Rotate(Vector3.up, Time.deltaTime * 50);
    }
    }
    }
     
  7. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    558
    Take a look at these scripts, this is what we use for testing this sort of thing. I use the scripts to spin an object I'm gazing at, or to move an object I'm gazing at. These are a little more complicated because they are designed to work in the editor as well.

    Setup Help on how to use these scripts. Using a simple scene with a cube 3 meters(z) from the main camera.

    Description:
    I have a scene with a simple cube in it, with my camera.

    On the Cube:
    Add the Keyword Responder and the Shape Controller Script.
    Don't forget to setup the Keywords

    upload_2016-8-23_15-16-16.png

    On the Main Camera put the Speech Controller script on it.

    This is Test scripts so my apologies is it is hard to read.
     

    Attached Files:

  8. spinteractive

    spinteractive

    Joined:
    Dec 19, 2015
    Posts:
    75
    Hi Welsey,
    It's got to be bug in Unity with Speech Commands.

    Here's a script that works on collections and mesh with click commands.
    When modified to accept voice commands it only works on direct mesh.
    All I did was change the input method, nothing else - Click to Voice -

    using UnityEngine;

    public class SpeakToPlaceParent : MonoBehaviour
    {
    bool move = false;

    AudioSource audioSource = null;
    AudioClip tapSound = null;

    void Start()
    {
    // Add an AudioSource component and set up some defaults
    audioSource = gameObject.AddComponent<AudioSource>();
    audioSource.playOnAwake = false;
    audioSource.spatialize = true;
    audioSource.spatialBlend = 1.0f;
    audioSource.dopplerLevel = 0.0f;
    audioSource.rolloffMode = AudioRolloffMode.Custom;

    // Load the Sphere sounds from the Resources folder
    tapSound = Resources.Load<AudioClip>("Impact");
    }

    // Called by SpeechManager when the user says the "Spin Object" command
    void Move()
    {
    move = true;
    SpatialMapping.Instance.DrawVisualMeshes = true;
    audioSource.clip = tapSound;
    audioSource.Play();
    }

    // Called by SpeechManager when the user says the "Stop Spinning" command
    void Place()
    {
    move = false;
    SpatialMapping.Instance.DrawVisualMeshes = false;
    audioSource.clip = tapSound;
    audioSource.Play();
    }

    // Update is called once per frame
    void Update()
    {
    // If the user is in placing mode,
    // update the placement to match the user's gaze.

    if (move)
    {
    // Do a raycast into the world that will only hit the Spatial Mapping mesh.
    var headPosition = Camera.main.transform.position;
    var gazeDirection = Camera.main.transform.forward;

    RaycastHit hitInfo;
    if (Physics.Raycast(headPosition, gazeDirection, out hitInfo,
    30.0f, SpatialMapping.PhysicsRaycastMask))
    {
    // Move this object's parent object to
    // where the raycast hit the Spatial Mapping mesh.
    this.transform.parent.position = hitInfo.point;

    // Rotate this object's parent object to face the user.
    Quaternion toQuat = Camera.main.transform.localRotation;
    toQuat.x = 0;
    toQuat.z = 0;
    this.transform.parent.rotation = toQuat;
    }
    }
    }
    }
     
  9. spinteractive

    spinteractive

    Joined:
    Dec 19, 2015
    Posts:
    75
    By the way, I'm building off of the code from the Origami demo.
    I'm trying to get your demo running - can I use the World Cursor from the Origami demo for Gaze?

    How come in my script above I can modify collections with Click input, but cannot with Voice Input?
     
  10. spinteractive

    spinteractive

    Joined:
    Dec 19, 2015
    Posts:
    75
    This is what I mean by collection. It's actually a model with a bunch of meshes.
     

    Attached Files:

  11. BrandonFogerty

    BrandonFogerty

    Joined:
    Jan 29, 2016
    Posts:
    83
    Hi @spinteractive,

    I put together a simple example that does what you are trying to do. I have attached my project to this post.

    Below is the result that I get with my implementation.


    I created a parent object in my scene. I created 3 cubes as children of the parent object. I wrote a "Rotater" script that rotates any GameObject. Then I attached the Rotater script to each cube. The Rotater script has a boolean variable called "Rotate". When it is true, the GameObject will rotate. When it is false, it will stop rotating.

    Lastly I have a "Commander" script. I added the Commander component to my Main Camera. The Commander script will set a Rotater component's Rotate variable to true or false. However the rotate variable will only be changed on a GameObject that is in the Camera's gaze or line of sight. In editor, you can change the rotation of the camera in the scene view to point at a cube and then press the "A" key to rotate it or the "Z" key to stop its rotation. On the HoloLens, you can look at a cube and say "start spinning" or "stop spinning".

    The following is a visual snapshot of my scene setup.
    hierarchy.png

    The following is the source code for both scripts.

    Rotater.cs
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Rotater : MonoBehaviour
    5. {
    6.     public bool Rotate = false;
    7.     public float SecondsToCompleteRotation = 5.0f;
    8.  
    9.     float timer = 0.0f;
    10.     Vector3 startingEulerAngles;
    11.     Vector3 endingEulerAngles;
    12.  
    13.     void Start ()
    14.     {
    15.         startingEulerAngles = this.transform.localRotation.eulerAngles;
    16.         endingEulerAngles = new Vector3(360.0f, 0.0f, 360.0f);
    17.     }
    18.  
    19.     void Update ()
    20.     {
    21.         if(!Rotate)
    22.         {
    23.             return;
    24.         }
    25.  
    26.         timer += Time.deltaTime;
    27.         float t = Mathf.Clamp01(timer/SecondsToCompleteRotation);
    28.  
    29.         Vector3 currentEulerAngles = Vector3.Slerp(startingEulerAngles, endingEulerAngles, t);
    30.  
    31.         Quaternion newRotation = Quaternion.Euler(currentEulerAngles);
    32.         this.transform.localRotation = newRotation;
    33.  
    34.         if(t >= 0.99f)
    35.         {
    36.             timer = 0.00f;
    37.         }
    38.     }
    39. }
    Commander.cs
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Windows.Speech;
    3.  
    4. public class Commander : MonoBehaviour
    5. {
    6.     private static readonly string VC_START_SPINNING = "start spinning";
    7.     private static readonly string VC_STOP_SPINNING = "stop spinning";
    8.  
    9.     KeywordRecognizer keywordRecognizer = null;
    10.  
    11.     void Start ()
    12.     {
    13.         string[] keywords = new string[]
    14.         {
    15.             VC_START_SPINNING,
    16.             VC_STOP_SPINNING
    17.         };
    18.  
    19.         keywordRecognizer = new KeywordRecognizer(keywords, ConfidenceLevel.Medium);
    20.         keywordRecognizer.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized;
    21.         keywordRecognizer.Start();
    22.     }
    23.  
    24.     void OnDestroy()
    25.     {
    26.         keywordRecognizer.Stop();
    27.     }
    28.  
    29.     private void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args)
    30.     {
    31.         GameObject focusObject = null;
    32.  
    33.         if(string.Equals(args.text, VC_START_SPINNING))
    34.         {
    35.             focusObject = GetGameObjectInFocus();
    36.             OnStartSpinning(focusObject);
    37.         }
    38.         else if(string.Equals(args.text, VC_STOP_SPINNING))
    39.         {
    40.             focusObject = GetGameObjectInFocus();
    41.             OnStopSpinning(focusObject);
    42.         }
    43.     }
    44.  
    45.     void Update ()
    46.     {
    47. #if UNITY_EDITOR
    48.         GameObject focusObject = null;
    49.         if(Input.GetKeyDown(KeyCode.A))
    50.         {
    51.             focusObject = GetGameObjectInFocus();
    52.             OnStartSpinning(focusObject);
    53.         }
    54.         else if(Input.GetKeyDown(KeyCode.Z))
    55.         {
    56.             focusObject = GetGameObjectInFocus();
    57.             OnStopSpinning(focusObject);
    58.         }
    59. #endif
    60.  
    61.     }
    62.  
    63.     GameObject GetGameObjectInFocus()
    64.     {
    65.         Ray ray = new Ray(  this.transform.position,
    66.                             this.transform.forward);
    67.  
    68.         RaycastHit hitInfo;
    69.         if(!Physics.Raycast(ray,out hitInfo,float.MaxValue))
    70.         {
    71.             return null;
    72.         }
    73.  
    74.         if(hitInfo.collider == null)
    75.         {
    76.             return null;
    77.         }
    78.  
    79.         return hitInfo.collider.gameObject;
    80.     }
    81.  
    82.     void OnStartSpinning(GameObject gameObjectToSpin)
    83.     {
    84.         if(gameObjectToSpin == null)
    85.         {
    86.             return;
    87.         }
    88.  
    89.         Rotater rotater = gameObjectToSpin.GetComponent<Rotater>();
    90.         if(rotater == null)
    91.         {
    92.             return;
    93.         }
    94.  
    95.         rotater.Rotate = true;
    96.     }
    97.  
    98.     void OnStopSpinning(GameObject gameObjectToSpin)
    99.     {
    100.         if(gameObjectToSpin == null)
    101.         {
    102.             return;
    103.         }
    104.  
    105.         Rotater rotater = gameObjectToSpin.GetComponent<Rotater>();
    106.         if(rotater == null)
    107.         {
    108.             return;
    109.         }
    110.  
    111.         rotater.Rotate = false;
    112.     }
    113. }
    I hope that helps!
     

    Attached Files:

  12. spinteractive

    spinteractive

    Joined:
    Dec 19, 2015
    Posts:
    75
    Thank you for the thorough response.
    Can you put that rotator script on the parent and spin all 3?
    And also move the entire collection to another point on the spatial mesh with a gaze-click.
    That's where I'm having problems.
    I can only Spin or Move a collection. Not both..
     
  13. spinteractive

    spinteractive

    Joined:
    Dec 19, 2015
    Posts:
    75
    Hi OK, heres a link to my project - https://1drv.ms/u/s!AkuWv2fljTZdhFzb96fg_SX9ukre

    There's a GestureManager & SpeechManager.
    There's a script called DiamondCommands.cs
    It let's you air-click objects to SPIN, and say 'MOVE DIAMOND / PLACE DIAMOND' to move & place objects.

    On the left object, it moves and places this object as I need.
    On the right object, it only Spin's the object - move does not work.

    The only difference I see is:
    On the left object, the script is being called on the mesh directly and it works both SPIN AND MOVE.
    On the right object , the script is being called on the parent - it only SPINs.

    Why is this happening? I need to move and spin collection of objects (parents).

    Thank you for your assistance and time I really appreciate :)
     

    Attached Files:

    Last edited: Aug 25, 2016
  14. BrandonFogerty

    BrandonFogerty

    Joined:
    Jan 29, 2016
    Posts:
    83
    Hi @spinteractive,

    In the following example, I am transforming the parent game object instead of directly transforming the three cubes.


    I added the the functionality to move a game object to the Rotater script. I also removed the box collider and rotater script from each of my cubes. Then I added a box collider to my parent game object. I made the box collider large enough to contain all three of the child cubes. Finally I added the rotater script to the parent object.

    Below is a snapshot of my scene setup.
    SpinningCubesPart2.png

    The following is the updated source code for both scripts.

    Rotater.cs
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Rotater : MonoBehaviour
    5. {
    6.     public bool Rotate = false;
    7.     public bool Move = false;
    8.     public float SecondsToCompleteRotation = 5.0f;
    9.     public float SecondsToCompleteMovement = 5.0f;
    10.  
    11.     float rotateTimer = 0.0f;
    12.     float moveTimer = 0.0f;
    13.  
    14.     Vector3 startingEulerAngles;
    15.     Vector3 endingEulerAngles;
    16.  
    17.     Vector3 startingPosition;
    18.     Vector3 endingPosition;
    19.  
    20.     void Start ()
    21.     {
    22.         startingEulerAngles = this.transform.localRotation.eulerAngles;
    23.         endingEulerAngles = new Vector3(360.0f,0.0f,360.0f);
    24.  
    25.         startingPosition = this.transform.localPosition;
    26.         endingPosition = startingPosition + (this.transform.localRotation * Vector3.up * 0.5f);
    27.     }
    28.  
    29.     void Update ()
    30.     {
    31.         RotateObject();
    32.         MoveObject();
    33.     }
    34.  
    35.     void RotateObject()
    36.     {
    37.         if(!Rotate)
    38.         {
    39.             return;
    40.         }
    41.  
    42.         rotateTimer += Time.deltaTime;
    43.         float t = Mathf.Clamp01(rotateTimer/SecondsToCompleteRotation);
    44.  
    45.         Vector3 currentEulerAngles = Vector3.Slerp(startingEulerAngles,endingEulerAngles,t);
    46.  
    47.         Quaternion newRotation = Quaternion.Euler(currentEulerAngles);
    48.         this.transform.localRotation = newRotation;
    49.  
    50.         if(t >= 0.99f)
    51.         {
    52.             rotateTimer = 0.00f;
    53.         }
    54.     }
    55.  
    56.     void MoveObject()
    57.     {
    58.         if(!Move)
    59.         {
    60.             return;
    61.         }
    62.  
    63.         moveTimer += Time.deltaTime;
    64.         float x = moveTimer/SecondsToCompleteMovement;
    65.         // Use an S curve to smooth out the motion.
    66.         float xPrime = x*x*(3.0f-2.0f*x);
    67.         float t = Mathf.Clamp01(xPrime);
    68.  
    69.         Vector3 newPosition = Vector3.Lerp(startingPosition, endingPosition, t);
    70.         this.transform.localPosition = newPosition;
    71.  
    72.         if(t >= 0.99f)
    73.         {
    74.             // Swap the position vectors around so we don't need
    75.             // to change the lerp code.
    76.             Vector3 tempPosition = startingPosition;
    77.             startingPosition = endingPosition;
    78.             endingPosition = tempPosition;
    79.  
    80.             moveTimer = 0.00f;
    81.         }
    82.     }
    83. }

    Commander.cs
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Windows.Speech;
    3.  
    4. public class Commander : MonoBehaviour
    5. {
    6.     private static readonly string VC_START_SPINNING = "start spinning";
    7.     private static readonly string VC_STOP_SPINNING = "stop spinning";
    8.     private static readonly string VC_START_MOVING = "start moving";
    9.     private static readonly string VC_STOP_MOVING = "stop moving";
    10.  
    11.     KeywordRecognizer keywordRecognizer = null;
    12.  
    13.     void Start ()
    14.     {
    15.         string[] keywords = new string[]
    16.         {
    17.             VC_START_SPINNING,
    18.             VC_STOP_SPINNING,
    19.             VC_START_MOVING,
    20.             VC_STOP_MOVING
    21.         };
    22.  
    23.         keywordRecognizer = new KeywordRecognizer(keywords, ConfidenceLevel.Medium);
    24.         keywordRecognizer.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized;
    25.         keywordRecognizer.Start();
    26.     }
    27.  
    28.     void OnDestroy()
    29.     {
    30.         keywordRecognizer.Stop();
    31.     }
    32.  
    33.     private void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args)
    34.     {
    35.         GameObject focusObject = null;
    36.  
    37.         if(string.Equals(args.text, VC_START_SPINNING))
    38.         {
    39.             focusObject = GetGameObjectInFocus();
    40.             OnStartSpinning(focusObject);
    41.         }
    42.         else if(string.Equals(args.text, VC_STOP_SPINNING))
    43.         {
    44.             focusObject = GetGameObjectInFocus();
    45.             OnStopSpinning(focusObject);
    46.         }
    47.         else if(string.Equals(args.text,VC_START_MOVING))
    48.         {
    49.             focusObject = GetGameObjectInFocus();
    50.             OnStartMoving(focusObject);
    51.         }
    52.         else if(string.Equals(args.text,VC_STOP_MOVING))
    53.         {
    54.             focusObject = GetGameObjectInFocus();
    55.             OnStopMoving(focusObject);
    56.         }
    57.     }
    58.  
    59. #if UNITY_EDITOR
    60.     void Update ()
    61.     {
    62.         GameObject focusObject = null;
    63.         if(Input.GetKeyDown(KeyCode.A))
    64.         {
    65.             focusObject = GetGameObjectInFocus();
    66.             OnStartSpinning(focusObject);
    67.         }
    68.         else if(Input.GetKeyDown(KeyCode.Z))
    69.         {
    70.             focusObject = GetGameObjectInFocus();
    71.             OnStopSpinning(focusObject);
    72.         }
    73.         else if(Input.GetKeyDown(KeyCode.S))
    74.         {
    75.             focusObject = GetGameObjectInFocus();
    76.             OnStartMoving(focusObject);
    77.         }
    78.         else if(Input.GetKeyDown(KeyCode.X))
    79.         {
    80.             focusObject = GetGameObjectInFocus();
    81.             OnStopMoving(focusObject);
    82.         }
    83.     }
    84. #endif
    85.  
    86.     GameObject GetGameObjectInFocus()
    87.     {
    88.         Ray ray = new Ray(  this.transform.position,
    89.                             this.transform.forward);
    90.  
    91.         RaycastHit hitInfo;
    92.         if(!Physics.Raycast(ray,out hitInfo,float.MaxValue))
    93.         {
    94.             return null;
    95.         }
    96.  
    97.         if(hitInfo.collider == null)
    98.         {
    99.             return null;
    100.         }
    101.  
    102.         return hitInfo.collider.gameObject;
    103.     }
    104.  
    105.     void OnStartSpinning(GameObject gameObject)
    106.     {
    107.         if(gameObject == null)
    108.         {
    109.             return;
    110.         }
    111.  
    112.         Rotater rotater = gameObject.GetComponent<Rotater>();
    113.         if(rotater == null)
    114.         {
    115.             return;
    116.         }
    117.  
    118.         rotater.Rotate = true;
    119.     }
    120.  
    121.     void OnStopSpinning(GameObject gameObject)
    122.     {
    123.         if(gameObject == null)
    124.         {
    125.             return;
    126.         }
    127.  
    128.         Rotater rotater = gameObject.GetComponent<Rotater>();
    129.         if(rotater == null)
    130.         {
    131.             return;
    132.         }
    133.  
    134.         rotater.Rotate = false;
    135.     }
    136.  
    137.     void OnStartMoving(GameObject gameObject)
    138.     {
    139.         if(gameObject == null)
    140.         {
    141.             return;
    142.         }
    143.  
    144.         Rotater rotater = gameObject.GetComponent<Rotater>();
    145.         if(rotater == null)
    146.         {
    147.             return;
    148.         }
    149.  
    150.         rotater.Move = true;
    151.     }
    152.  
    153.     void OnStopMoving(GameObject gameObject)
    154.     {
    155.         if(gameObject == null)
    156.         {
    157.             return;
    158.         }
    159.  
    160.         Rotater rotater = gameObject.GetComponent<Rotater>();
    161.         if(rotater == null)
    162.         {
    163.             return;
    164.         }
    165.  
    166.         rotater.Move = false;
    167.     }
    168. }
    Attached is the update Unity project.

    I hope that helps!
     

    Attached Files:

  15. spinteractive

    spinteractive

    Joined:
    Dec 19, 2015
    Posts:
    75
    Hi Brandon.
    Thanks for the awesome demo. really cool!
    OK, one additional thing I am doing, that your are not, is ray-casting to the objects, and to the spatial mesh.
    Maybe that it preventing something.
    I still haven't figured out my problem. It's driving me nuts.

    I can only make them move and rotate with gestures - my speech doesn't work.

    Move:

    Rotate:


    Looking at your code and project. Thanks.
    Alex
     
    Last edited: Aug 25, 2016
  16. spinteractive

    spinteractive

    Joined:
    Dec 19, 2015
    Posts:
    75
    Here the speech manager and command script are on the mesh. This works with gesture and speech. The speech command is heard and gestures works. This is good but it's only affecting the bottom mesh (it needs to work on the parent)

    WORKS.png


    Here the speech manager and command script are on the parent. This only works with gesture. The speech command does not work. WHY NOT??? (Is it a collider issue?) I NEED THIS TO WORK LIKE ABOVE - BUT IT MUST BE ON THE PARENT TO AFFECT THE ENTIRE OBJECT

    DOESNT WORK.png

    Here's the video:
     
    Last edited: Aug 26, 2016
  17. spinteractive

    spinteractive

    Joined:
    Dec 19, 2015
    Posts:
    75
    I figured out my problem. If putting a mesh collider on a parent, you need to assign a mesh to it, or use some other type of collider - for voice commands. For some reason, the gestures work as any level in the hierarchy.

    IT WORKS!!!!
     
    Last edited: Aug 26, 2016
    BrandonFogerty likes this.