Example #1
0
        public void MoveTowardsTest()
        {
            PositionF p1 = new PositionF(3, 3);
            PositionF p2 = new PositionF(4, 4);
            float     maxDistanceDelta = 2;

            PositionF p3 = PositionF.MoveTowards(p1, p2, maxDistanceDelta);
            PositionF p4 = PositionF.MoveTowards(p1, p2, 0);
            PositionF p5 = PositionF.MoveTowards(p2, p2, maxDistanceDelta);

            Assert.AreEqual(p2, p3);
            Assert.AreEqual(p1, p4);
            Assert.AreEqual(p2, p5);
        }
Example #2
0
        public void Update(float deltaTime)
        {
            if (Unit.PositionF == _targetPosition && Unit.Position == Unit.TargetPosition)
            {
                State = States.Stay;
                Path  = null;
            }

            if (State == States.Stay)
            {
                return;
            }

            Unit.PositionF = PositionF.MoveTowards(Unit.PositionF, _targetPosition, Speed * deltaTime);
        }