コード例 #1
0
        public void MoveAgent(
            float ahead           = 0,
            float right           = 0,
            float speed           = 1,
            float?fixedDeltaTime  = null,
            bool returnToStart    = true,
            bool disableRendering = true
            )
        {
            if (ahead == 0 && right == 0)
            {
                throw new ArgumentException("Must specify ahead or right!");
            }
            Vector3 direction           = new Vector3(x: right, y: 0, z: ahead);
            float   fixedDeltaTimeFloat = fixedDeltaTime.GetValueOrDefault(Time.fixedDeltaTime);

            CollisionListener collisionListener = this.GetComponentInParent <CollisionListener>();

            Vector3 directionWorld = transform.TransformDirection(direction);
            Vector3 targetPosition = transform.position + directionWorld;

            collisionListener.Reset();

            IEnumerator move = ContinuousMovement.move(
                controller: this,
                collisionListener: collisionListener,
                moveTransform: this.transform,
                targetPosition: targetPosition,
                fixedDeltaTime: fixedDeltaTimeFloat,
                unitsPerSecond: speed,
                returnToStartPropIfFailed: returnToStart,
                localPosition: false
                );

            if (disableRendering)
            {
                unrollSimulatePhysics(
                    enumerator: move,
                    fixedDeltaTime: fixedDeltaTimeFloat
                    );
            }
            else
            {
                StartCoroutine(move);
            }
        }
コード例 #2
0
        public void RotateAgent(
            float degrees,
            float speed             = 1.0f,
            bool waitForFixedUpdate = false,
            bool returnToStart      = true,
            bool disableRendering   = true,
            float fixedDeltaTime    = 0.02f
            )
        {
            CollisionListener collisionListener = this.GetComponentInParent <CollisionListener>();

            collisionListener.Reset();

            // this.transform.Rotate()
            IEnumerator rotate = ContinuousMovement.rotate(
                controller: this,
                collisionListener: this.GetComponentInParent <CollisionListener>(),
                moveTransform: this.transform,
                targetRotation: this.transform.rotation * Quaternion.Euler(0.0f, degrees, 0.0f),
                fixedDeltaTime: disableRendering ? fixedDeltaTime : Time.fixedDeltaTime,
                radiansPerSecond: speed,
                returnToStartPropIfFailed: returnToStart
                );

            if (disableRendering)
            {
                unrollSimulatePhysics(
                    enumerator: rotate,
                    fixedDeltaTime: fixedDeltaTime
                    );
            }
            else
            {
                StartCoroutine(rotate);
            }
        }