Example #1
0
        public void SetPosition(IGameObject owner, Entity.Vector targetPosition)
        {
            currentPosition        = targetPosition;
            lastPositionUpdateTime = GlobalClock.Now;

            currentVelocity.Reset();
        }
Example #2
0
        public Entity.Vector GetCurrentPosition(IGameObject owner)
        {
            if (!currentVelocity.IsZero())
            {
                var now = GlobalClock.Now;

                if (now != lastPositionUpdateTime)
                {
                    var elapsed      = now - lastPositionUpdateTime;
                    var nextPosition = currentPosition.Add(currentVelocity.Multiply(elapsed));

                    var currentToTarget = targetPosition.Diff(currentPosition);
                    var nextToTarget    = targetPosition.Diff(nextPosition);

                    if (currentToTarget.Dot(nextToTarget) < 0)
                    {
                        currentPosition = targetPosition;
                        Stop(owner);
                    }
                    else
                    {
                        currentPosition = nextPosition;
                    }
                }

                lastPositionUpdateTime = now;
            }
            return(currentPosition);
        }
Example #3
0
        public void WalkTo(IGameObject owner, Entity.Vector targetPosition)
        {
            this.targetPosition = targetPosition;

            var diff = targetPosition.Diff(GetCurrentPosition(owner));

            diff.Normalize();
            lastPositionUpdateTime = GlobalClock.Now;
            currentVelocity        = diff.Multiply(maxVelocity);
        }