示例#1
0
    private bool UpdateReturn()
    {
        MoveEditor.ProjectileEventProperties projectileProps = _projectileEventInfo._projectileProperties;
        float distanceDelta = projectileProps._reattachmentVelocity * Time.deltaTime;

        AttributeData attr                = _owner.OnGetAttributeData("GetAnimator");
        Animator      ownerAnimator       = attr.Animator;
        Transform     attachmentTransform = MoveEditor.MoveUtils.GetBodyPartTransform(ownerAnimator, projectileProps._reattachment, projectileProps._reattachmentPath);

        Vector3 attachmentPosition = attachmentTransform.TransformPoint(projectileProps._reattachmentOffset);

        bool       flipped  = false; //_owner.ID == 1;
        Quaternion rotation = Quaternion.Euler(projectileProps._reattachmentAngles);
        Quaternion attachmentOrientation = Quaternion.identity;

        if (projectileProps._reattachmentIsWorldSpace)
        {
            attachmentOrientation = rotation;
            if (flipped)
            {
                // rotate this by 180
                transform.RotateAround(transform.position, Vector3.up, 180.0f);
            }
        }
        else
        {
            attachmentOrientation = attachmentTransform.rotation * rotation;
        }

        if (flipped)
        {
            // mirror!
            attachmentOrientation = FlipRotation(attachmentOrientation);
        }

        float distance = Vector3.Distance(attachmentPosition, transform.position);

        if (distance > distanceDelta)
        {
            Vector3    pos = Vector3.MoveTowards(transform.position, attachmentPosition, distanceDelta);
            Quaternion q   = Quaternion.RotateTowards(transform.rotation, attachmentOrientation, projectileProps._reattachmentAngularVelocity);

            transform.position = pos;
            transform.rotation = q;
        }
        else
        {
            transform.position = attachmentPosition;
            transform.rotation = attachmentOrientation;

            return(true);
        }

        return(false);
    }
示例#2
0
    public void Activate(Animator ownerAnimator, MoveEditor.ProjectileEventInfo projectileEventInfo, OnProjectileDeactivated callback, bool flipped)
    {
        _projectileEventInfo = projectileEventInfo;
        _deactivateCallback  = callback;
        MoveEditor.ProjectileEventProperties projectileProperties = projectileEventInfo._projectileProperties;

        Transform spawnTransform = MoveEditor.MoveUtils.GetBodyPartTransform(ownerAnimator, projectileProperties._spawnAttachment, projectileProperties._spawnAttachmentPath);

        _speed = projectileProperties._initialVelocity;

        transform.parent        = spawnTransform;
        transform.localPosition = projectileProperties._spawnOffset;

        if (projectileProperties._worldSpace)
        {
            transform.eulerAngles = projectileProperties._spawnAngles;

            if (flipped)
            {
                // rotate this by 180
                transform.RotateAround(transform.position, Vector3.up, 180.0f);
            }
        }
        else
        {
            transform.localEulerAngles = projectileProperties._spawnAngles;
        }

        // mirror the effect, for parented effects, this is done inside the attach transform
        if (flipped)
        {
            transform.rotation = FlipRotation(transform.rotation);
        }

        transform.parent     = null;
        transform.localScale = Vector3.one;

        // play all on spawn events
        PlayEffects(_onSpawnEvents);

        //_previousPosition = transform.position;

        _state = ProjectileState.kSpwaned;

        #region [GM] Projectile.
        if (_projectileEventInfo._projectileProperties._autoVelocity)
        {
            CalculateAutoVelocity();
            _state = ProjectileState.kSpwaned;             // don't displace on kSpwaned (will go to kActive on next frame)
        }
        #endregion

        _startTime = Time.realtimeSinceStartup;
        _duration  = 1.0f;
        if (_owner != null)
        {
            AttributeData attr     = _owner.OnGetAttributeData("GetTargetPosition");
            float         distance = Vector3.Distance(GetCenter(), attr.TargetPosition);
            _duration = distance / _speed;
        }
    }