예제 #1
0
        public override void _PhysicsProcess(float delta)
        {
            Transform lerpT;

            switch (_moveState)
            {
            case MoveState.Pending:
                StartMove();
                break;

            case MoveState.Turning:
                lerpT = _lookFrom.InterpolateWith(_moveFrom, _moveTime);
                _body.GlobalTransform = lerpT;

                if (_turnTimeTotal <= 0)
                {
                    _turnTimeTotal = 2;
                }
                _moveTime += (delta / _turnTimeTotal);
                if (_moveTime >= 1)
                {
                    _moveState = MoveState.Moving;
                    _moveTime  = 0;
                }
                break;

            case MoveState.Moving:
                // lerp
                lerpT = _moveFrom.InterpolateWith(_moveTo, _moveTime);
                // directly lerp rotation and position
                _body.GlobalTransform = lerpT;

                // just apply position and look at the target
                //Transform realT = GlobalTransform;
                //realT.origin = lerpT.origin;
                //_body.GlobalTransform = realT;
                //LookAt(to.origin, to.basis.y);

                // update move time
                if (_moveTimeTotal <= 0)
                {
                    _moveTimeTotal = 10;
                }
                _moveTime += (delta / _moveTimeTotal);
                //Console.WriteLine($"MoveTime {_moveTime}");
                //_moveTime += delta;
                if (_moveTime >= 1)
                {
                    InfoPath path = Main.i.game.GetPathNode(firstPathName);
                    if (path == null)
                    {
                        _moveState = MoveState.None;
                        return;
                    }
                    _moveState    = MoveState.Pending;
                    firstPathName = path.nextPathName;
                }
                break;
            }
        }
예제 #2
0
        private void StartMove()
        {
            //Console.WriteLine($"Ent tank start move");
            InfoPath path = Main.i.game.GetPathNode(firstPathName);

            if (path == null)
            {
                _moveState = MoveState.None;
                return;
            }
            // final destination
            _moveTo         = path.GlobalTransform;
            _moveTo.origin += _bodyOffset;             // janky fix because body is not on the floor
            // turn start == current
            _lookFrom = _body.GlobalTransform;
            // finished turn == move start
            _moveFrom = _lookFrom.LookingAt(_moveTo.origin, _lookFrom.basis.y);
            // overwrite move to dir with look at dir,
            _moveTo.basis = _moveFrom.basis;

            //Console.WriteLine($"Look from: {_lookFrom}");
            //Console.WriteLine($"Move from: {_moveFrom}");
            //Console.WriteLine($"Move To: {_moveTo}");

            _moveTime  = 0;
            _moveState = MoveState.Turning;
        }