Пример #1
0
    public override void startWithTarget(Node target)
    {
        base.startWithTarget(target);

        _eFromType = kTypeProjectile;
        NodeWithHeight rendererTarget = target as NodeWithHeight;

        _oStartPos   = rendererTarget.position;
        _oEndPos     = _unit.Node.position;
        _fFromHeight = rendererTarget.height;

        _oDeltaPos = _oEndPos - _oStartPos;
        _fMinSpeed = Mathf.Sqrt(_oDeltaPos.x * _oDeltaPos.x + _oDeltaPos.y * _oDeltaPos.y) / _duration;
    }
Пример #2
0
    public override void update(float time)
    {
        if (!_target)
        {
            return;
        }

        Unit _u = _unit;

        if (_u != null)
        {
            _oEndPos   = _u.Node.position;
            _fToHeight = _u.Node.height + _u.Node.HalfOfHeight;
        }

        _oDeltaPos    = _oEndPos - _oStartPos;
        _fDeltaHeight = _fToHeight - _fFromHeight;

        float distance = Mathf.Sqrt(_oDeltaPos.x * _oDeltaPos.x + _oDeltaPos.y * _oDeltaPos.y);

        _duration = distance / _fMinSpeed;

        // 抛物线
        float fA = distance;
        float fX = time * fA - fA / 2;

        fA = -4 * _fMaxHeightDelta / (fA * fA);
        float fHeightDelta = fA * fX * fX + _fMaxHeightDelta;

        NodeWithHeight target = _target as NodeWithHeight;

        target.position = _oStartPos + _oDeltaPos * time;
        target.height   = _fFromHeight + _fDeltaHeight * time + fHeightDelta;

        if (_bFixRotation)
        {
            // 修正角度
            //float fOffsetR = Mathf.Atan(fA * fX);
            target.rotation = (
                Mathf.Atan2(_oEndPos.y - _oStartPos.y, _oEndPos.x - _oStartPos.x) +
                (_oStartPos.x < _oEndPos.x ? Mathf.Atan(fA * fX) : -Mathf.Atan(fA * fX))
                ) * Mathf.Rad2Deg;
        }
    }