Beispiel #1
0
        protected virtual void Update()
        {
            //keep a record of its old position so we can update its cell later
            //in this method
            Vector2 OldPos = Position;


            Vector2 SteeringForce = new Vector2();

            //calculate the combined force from each steering behavior in the
            //vehicle's list
            SteeringForce = Behaviors.SummingForce();

            //Acceleration = Force/Mass
            Vector2 acceleration = SteeringForce / _mass;

            //update velocity
            _velocity += acceleration * Time.deltaTime;

            //make sure vehicle does not exceed maximum velocity
            _velocity = _velocity.Truncate(_maxSpeed);

            //把本地速度转成世界坐标
            Vector4 worldVec = new Vector4(_velocity.x, _velocity.y, 0, 1);

            //update the position
            Position += worldVec.ToVector2() * Scale * Time.deltaTime;

            //update the heading if the vehicle has a non zero velocity
            if (_velocity.sqrMagnitude > float.Epsilon)
            {
                _heading = _velocity.normalized;

                _side = _heading.Perpendicular();
            }

            //EnforceNonPenetrationConstraint(this, World()->Agents());

            /*
             * //treat the screen as a toroid
             * WrapAround(m_vPos, m_pWorld->cxClient(), m_pWorld->cyClient());
             */

            //update the vehicle's current cell if space partitioning is turned on

            /*
             * if (Steering.IsSpacePartitioningOn())
             * {
             *  World.CellSpace.UpdateEntity(this, OldPos);
             * }
             */

            if (IsSmoothingOn())
            {
                //_smoothedHeading = _headingSmoother.Update(Heading);
            }
            transform.rotation = GetRotation();
        }