Ejemplo n.º 1
0
        /**
         * <summary>Forces the object to move along a DragTrack without the player's direct input.</summary>
         * <param name = "_targetTrackValue">The intended proportion along the track to send the object to</param>
         * <param name = "_targetTrackSpeed">The intended speed to move the object by</param>
         * <param name = "removePlayerControl">If True and the player is currently moving the object, then player control will be removed</param>
         * <param name = "layerMask">A LayerMask that determines what collisions will cause the automatic movement to cease</param>
         * <param name = "snapID">The ID number of the associated snap, if snapping</param>
         */
        public void AutoMoveAlongTrack(float _targetTrackValue, float _targetTrackSpeed, bool removePlayerControl, LayerMask layerMask, int snapID = -1)
        {
            if (dragMode == DragMode.LockToTrack && track != null)
            {
                if (snapID < 0)
                {
                    canCallSnapEvents = true;
                }

                if (_targetTrackSpeed <= 0f)
                {
                    activeAutoMove = null;
                    track.SetPositionAlong(_targetTrackValue, this);
                    return;
                }

                if (removePlayerControl)
                {
                    isHeld = false;
                }

                activeAutoMove = new AutoMoveTrackData(_targetTrackValue, _targetTrackSpeed / 6000f, layerMask, snapID);
            }
            else
            {
                ACDebug.LogWarning("Cannot move " + this.name + " along a track, because no track has been assigned to it", this);
            }
        }
Ejemplo n.º 2
0
        /**
         * <summary>Snaps the object to a track at a given position along it</summary>
         * <param name="newTrack">The new DragTrack to snap to</param>
         * <param name="positionAlong">How far along the track, as a decimal of its length, to snap to</param>
         */
        public void SnapToTrack(DragTrack newTrack, float positionAlong)
        {
            if (newTrack == null)
            {
                return;
            }

            if (track && newTrack != track)
            {
                track.OnDisconnect(this);
            }

            dragMode = DragMode.LockToTrack;

            if (IsAutoMoving())
            {
                activeAutoMove.Stop(track, this, true);
                activeAutoMove = null;
            }

            track = newTrack;
            track.SetPositionAlong(positionAlong, this);

            if (_rigidbody)
            {
                _rigidbody.velocity        = Vector3.zero;
                _rigidbody.angularVelocity = Vector3.zero;
            }
        }
Ejemplo n.º 3
0
 /**
  * <summary>Stops the object from moving without the player's direct input (i.e. through Actions).</summary>
  * <param name = "snapToTarget">If True, then the object will snap instantly to the intended target position</param>
  */
 public void StopAutoMove(bool snapToTarget = true)
 {
     if (IsAutoMoving())
     {
         activeAutoMove.Stop(track, this, snapToTarget);
         activeAutoMove             = null;
         _rigidbody.velocity        = Vector3.zero;
         _rigidbody.angularVelocity = Vector3.zero;
     }
 }