예제 #1
0
        public void Update(Entity entity, float deltaTime)
        {
            C_MoveToTarget c = entity.GetComp <C_MoveToTarget>();

            if (MapUtils.CloseEnough(entity.GetPosition(), c.targetPos))
            {
                return;
            }

            Vector2 pos = entity.GetPosition();
            Vector2 dir = c.targetPos - pos;

            dir.Normalize();
            pos += deltaTime * c.speed * dir;
            entity.SetRotation(VectorExt.ToRotation(dir));
            entity.SetPosition(pos);
        }
예제 #2
0
        private void Update(Entity entity, float deltaTime)
        {
            C_MoveToPos c = entity.GetComp <C_MoveToPos>();

            Vector2 targetPos = entity.GetComp <C_TargetPos>().targetPos;
            float   move      = deltaTime * c.speed;

            if (MapUtils.CloseEnough(entity.GetPosition(), targetPos, move))
            {
                entity.SetPosition(targetPos);
                entity.AddComp <C_MoveEnd>();
                return;
            }

            Vector2 pos = entity.GetPosition();
            Vector2 dir = targetPos - pos;

            dir.Normalize();
            pos += move * dir;
            entity.SetRotation(VectorExt.ToRotation(dir));
            entity.SetPosition(pos);
        }