예제 #1
0
        // Token: 0x0600079F RID: 1951 RVA: 0x00049E78 File Offset: 0x00048278
        public void Update()
        {
            if (this.rvoAgent == null)
            {
                return;
            }
            if (this.lastPosition != this.tr.position)
            {
                this.Teleport(this.tr.position);
            }
            if (this.lockWhenNotMoving)
            {
                this.locked = (this.desiredVelocity == Vector3.zero);
            }
            this.UpdateAgentProperties();
            Vector3 interpolatedPosition = this.rvoAgent.InterpolatedPosition;

            interpolatedPosition.y = this.adjustedY;
            RaycastHit raycastHit;

            if (this.mask != 0 && Physics.Raycast(interpolatedPosition + Vector3.up * this.height * 0.5f, Vector3.down, out raycastHit, float.PositiveInfinity, this.mask))
            {
                this.adjustedY = raycastHit.point.y;
            }
            else
            {
                this.adjustedY = 0f;
            }
            interpolatedPosition.y = this.adjustedY;
            this.rvoAgent.SetYPosition(this.adjustedY);
            Vector3 a = Vector3.zero;

            if (this.wallAvoidFalloff > 0f && this.wallAvoidForce > 0f)
            {
                List <ObstacleVertex> neighbourObstacles = this.rvoAgent.NeighbourObstacles;
                if (neighbourObstacles != null)
                {
                    for (int i = 0; i < neighbourObstacles.Count; i++)
                    {
                        Vector3 position  = neighbourObstacles[i].position;
                        Vector3 position2 = neighbourObstacles[i].next.position;
                        Vector3 vector    = this.position - AstarMath.NearestPointStrict(position, position2, this.position);
                        if (!(vector == position) && !(vector == position2))
                        {
                            float sqrMagnitude = vector.sqrMagnitude;
                            vector /= sqrMagnitude * this.wallAvoidFalloff;
                            a      += vector;
                        }
                    }
                }
            }
            this.rvoAgent.DesiredVelocity = this.desiredVelocity + a * this.wallAvoidForce;
            this.tr.position  = interpolatedPosition + Vector3.up * this.height * 0.5f - this.center;
            this.lastPosition = this.tr.position;
            if (this.enableRotation && this.velocity != Vector3.zero)
            {
                base.transform.rotation = Quaternion.Lerp(base.transform.rotation, Quaternion.LookRotation(this.velocity), Time.deltaTime * this.rotationSpeed * Mathf.Min(this.velocity.magnitude, 0.2f));
            }
        }
예제 #2
0
        public void Update()
        {
            if (rvoAgent == null)
            {
                return;
            }

            if (lastPosition != tr.position)
            {
                Teleport(tr.position);
            }

            if (lockWhenNotMoving)
            {
                locked = desiredVelocity == Vector3.zero;
            }

            UpdateAgentProperties();
            FindNeighour();
            //CancelMess ();
            //NotifyNeighoursReached ();
            RaycastHit hit;

            //The non-interpolated position
            Vector3 realPos = rvoAgent.InterpolatedPosition;

            realPos.y = adjustedY;

            if (mask != 0 && Physics.Raycast(realPos + Vector3.up * height * 0.5f, Vector3.down, out hit, float.PositiveInfinity, mask))
            {
                adjustedY = hit.point.y;
            }
            else
            {
                adjustedY = 0;
            }
            realPos.y = adjustedY;

            rvoAgent.Position = new Vector3(rvoAgent.Position.x, adjustedY, rvoAgent.Position.z);

            Vector3 force = Vector3.zero;

            if (wallAvoidFalloff > 0 && wallAvoidForce > 0)
            {
                List <ObstacleVertex> obst = rvoAgent.NeighbourObstacles;

                if (obst != null)
                {
                    for (int i = 0; i < obst.Count; i++)
                    {
                        Vector3 a = obst[i].position;
                        Vector3 b = obst[i].next.position;

                        Vector3 closest = position - AstarMath.NearestPointStrict(a, b, position);

                        if (closest == a || closest == b)
                        {
                            continue;
                        }

                        float dist = closest.sqrMagnitude;
                        closest /= dist * wallAvoidFalloff;
                        force   += closest;
                    }
                }
            }

        #if ASTARDEBUG
            Debug.DrawRay(position, desiredVelocity + force * wallAvoidForce);
        #endif

//			Vector3 dir = goals[i] - realPos;
//			dir = Vector3.ClampMagnitude (dir,1);
//			agents[i].DesiredVelocity = dir * agents[i].MaxSpeed;

            rvoAgent.DesiredVelocity = desiredVelocity + force * wallAvoidForce;

            tr.position  = realPos + Vector3.up * height * 0.5f - center;
            lastPosition = tr.position;

            if (enableRotation && velocity != Vector3.zero)
            {
                transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(velocity), Time.deltaTime * rotationSpeed * Mathf.Min(velocity.magnitude, 0.2f));
            }
        }
        public void Update()
        {
            if (lastPosition != tr.position)
            {
                Teleport(tr.position);
            }

            if (lockWhenNotMoving)
            {
                locked = desiredVelocity == Vector3.zero;
            }

            UpdateAgentProperties();

            RaycastHit hit;

            //The non-interpolated position
            Vector3 realPos = rvoAgent.InterpolatedPosition;

            realPos.y = adjustedY;

            if (mask != 0 && Physics.Raycast(realPos + Vector3.up * height * 0.5f, Vector3.down, out hit, float.PositiveInfinity, mask))
            {
                adjustedY = hit.point.y;
            }
            else
            {
                adjustedY = 0;
            }
            realPos.y = adjustedY;

            rvoAgent.Position = new Vector3(rvoAgent.Position.x, adjustedY, rvoAgent.Position.z);

            Vector3 force = Vector3.zero;

            if (wallAvoidFalloff > 0 && wallAvoidForce > 0)
            {
                List <ObstacleVertex> obst = rvoAgent.NeighbourObstacles;

                for (int i = 0; i < obst.Count; i++)
                {
                    Vector3 a = obst[i].position;
                    Vector3 b = obst[i].next.position;

                    Vector3 closest = position - AstarMath.NearestPointStrict(a, b, position);

                    if (closest == a || closest == b)
                    {
                        continue;
                    }

                    float dist = closest.sqrMagnitude;
                    closest /= dist * wallAvoidFalloff;
                    force   += closest;
                }
            }

        #if ASTARDEBUG
            Debug.DrawRay(position, desiredVelocity + force * wallAvoidForce);
        #endif
            rvoAgent.DesiredVelocity = desiredVelocity + force * wallAvoidForce;

            tr.position  = realPos + Vector3.up * height * 0.5f - center;
            lastPosition = tr.position;
        }