SetTargetPosition() public method

Sets the target position for the transform and if position wasn't already animating, fires the InterpolationStarted event.
public SetTargetPosition ( Vector3 target ) : void
target UnityEngine.Vector3 The new target position to for the transform.
return void
Ejemplo n.º 1
0
        // Update is called once per frame
        private void Update()
        {
            if (Manipulating)
            {
                // First step is to figure out the delta between the initial manipulation position and the current manipulation position
                Vector3 localManipulationPosition = Camera.main.transform.InverseTransformPoint(gestureManager.ManipulationPosition);
                Vector3 initialToCurrentPosition  = localManipulationPosition - initialManipulationPosition;

                // When performing a manipulation gesture, the manipulation generally only translates a relatively small amount.
                // If we move the object only as much as the input source itself moves, users can only make small adjustments before
                // the source is lost and the gesture completes.  To improve the usability of the gesture we scale each
                // axis of movement by some amount (camera relative).  This value can be changed in the editor or
                // at runtime based on the needs of individual movement scenarios.
                Vector3 scaledLocalPositionDelta = Vector3.Scale(initialToCurrentPosition, PositionScale);

                // Once we've figured out how much the object should move relative to the camera we apply that to the initial
                // camera relative position.  This ensures that the object remains in the appropriate location relative to the camera
                // and the input source as the camera moves.  The allows users to use both gaze and gesture to move objects.  Once they
                // begin manipulating an object they can rotate their head or walk around and the object will move with them
                // as long as they maintain the gesture, while still allowing adjustment via input movement.
                Vector3 localObjectPosition = initialObjectPosition + scaledLocalPositionDelta;
                Vector3 worldObjectPosition = Camera.main.transform.TransformPoint(localObjectPosition);

                // If the object has an interpolator we should use it, otherwise just move the transform directly
                if (targetInterpolator != null)
                {
                    targetInterpolator.SetTargetPosition(worldObjectPosition);
                }
                else
                {
                    transform.position = worldObjectPosition;
                }
            }
        }
        protected virtual void Update()
        {
            // Retrieve the frustum planes from the camera.
            frustumPlanes = GeometryUtility.CalculateFrustumPlanes(TagAlongView);

            // Determine if the Tagalong needs to move based on whether its
            // BoxCollider is in or out of the camera's view frustum.
            Vector3 tagalongTargetPosition;

            if (CalculateTagalongTargetPosition(transform.position, out tagalongTargetPosition))
            {
                // Derived classes will use the same Interpolator and may have
                // adjusted its PositionUpdateSpeed for some other purpose.
                // Restore the value we care about and tell the Interpolator
                // to move the Tagalong to its new target position.
                interpolator.PositionPerSecond = PositionUpdateSpeed;
                interpolator.SetTargetPosition(tagalongTargetPosition);
            }
            else if (!interpolator.Running && EnforceDistance)
            {
                // If the Tagalong is inside the camera's view frustum, and it is
                // supposed to stay a fixed distance from the camera, force the
                // tagalong to that location (without using the Interpolator).
                Ray ray = new Ray(TagAlongView.transform.position, transform.position - TagAlongView.transform.position);
                transform.position = ray.GetPoint(TagalongDistance);
            }
        }
Ejemplo n.º 3
0
        // Update is called once per frame
        private void Update()
        {
            if (Navigating)
            {
                // First step is to figure out the delta between the initial navigation position and the current navigation position
                // commented out as turning head affected the rotation of the ColorWheel. Will evaluate with user testing
                //Vector3 localNavigationPosition = Camera.main.transform.InverseTransformPoint(gestureManager.ManipulationPosition);
                //Vector3 initialToCurrentPosition = gestureManager.ManipulationPosition - initialNavigationPosition;

                //Vector3 localManipulationPosition = Camera.main.transform.InverseTransformPoint(gestureManager.ManipulationPosition);
                //Vector3 initialToCurrentPosition = localManipulationPosition - initialManipulationPosition;

                //// When performing a navigation gesture, the navigation generally only translates a relatively small amount.
                //// If we rotate the object only as much as the input source itself moves, users can only make small adjustments before
                //// the source is lost and the gesture completes.  To improve the usability of the gesture we scale each
                //// axis of movement by some amount (camera relative).  This value can be changed in the editor or
                //// at runtime based on the needs of individual movement scenarios.

                //// If PositionScale is set high to increase sensitivity, unfortunately it also increases the minimum travel distance
                //// needed to begin triggering movement. To fix this, a dynamicSensitivity var is used to counter the minimum travel
                ////Vector3 scaledLocalPositionDelta;
                ////if (dynamicSensitivity < PositionScale.y)
                ////{
                ////    scaledLocalPositionDelta = Vector3.Scale(initialToCurrentPosition, new Vector3(PositionScale.x, dynamicSensitivity, PositionScale.z));
                ////    dynamicSensitivity += 0.2f;
                ////}
                ////else
                ////{
                ////    scaledLocalPositionDelta = Vector3.Scale(initialToCurrentPosition, PositionScale);
                ////}
                //Vector3 scaledLocalPositionDelta = Vector3.Scale(initialToCurrentPosition, PositionScale);

                //// Once we've figured out how much the object should rotate relative to the camera we apply that to the initial
                //// camera relative position.  This ensures that the object remains in the appropriate location relative to the camera
                //// and the input source as the camera moves.  The allows users to use both gaze and gesture to move objects.  Once they
                //// begin navigating an object they can rotate their head or walk around and the object will move with them
                //// as long as they maintain the gesture, while still allowing adjustment via input movement.
                //Vector3 localObjectPosition = initialObjectPosition + scaledLocalPositionDelta;
                //Vector3 worldObjectPosition = Camera.main.transform.TransformPoint(localObjectPosition);

                //// If the object has an interpolator we should use it, otherwise just move the transform directly
                //if (targetInterpolator != null)
                //{
                //    targetInterpolator.SetTargetPosition(localObjectPosition);
                //}
                //else
                //{
                //    navigatorActions.ActionController(localObjectPosition);
                //}
                //initialObjectPosition = initialToCurrentPosition;

                // First step is to figure out the delta between the initial manipulation position and the current manipulation position
                Vector3 localManipulationPosition = Camera.main.transform.InverseTransformPoint(gestureManager.ManipulationPosition);
                Vector3 initialToCurrentPosition  = localManipulationPosition - initialNavigationPosition;

                // When performing a manipulation gesture, the manipulation generally only translates a relatively small amount.
                // If we move the object only as much as the input source itself moves, users can only make small adjustments before
                // the source is lost and the gesture completes.  To improve the usability of the gesture we scale each
                // axis of movement by some amount (camera relative).  This value can be changed in the editor or
                // at runtime based on the needs of individual movement scenarios.
                Vector3 scaledLocalPositionDelta = Vector3.Scale(initialToCurrentPosition, PositionScale);

                // Once we've figured out how much the object should move relative to the camera we apply that to the initial
                // camera relative position.  This ensures that the object remains in the appropriate location relative to the camera
                // and the input source as the camera moves.  The allows users to use both gaze and gesture to move objects.  Once they
                // begin manipulating an object they can rotate their head or walk around and the object will move with them
                // as long as they maintain the gesture, while still allowing adjustment via input movement.
                Vector3 localObjectPosition = initialObjectPosition + scaledLocalPositionDelta;
                Vector3 worldObjectPosition = Camera.main.transform.TransformPoint(localObjectPosition);

                // If the object has an interpolator we should use it, otherwise just move the transform directly
                if (targetInterpolator != null)
                {
                    targetInterpolator.SetTargetPosition(localObjectPosition);
                }
                else
                {
                    navigatorActions.ActionController(localObjectPosition);
                    //transform.position = worldObjectPosition;
                }
            }
        }