예제 #1
0
        public IkModifier(ModifierInfo mi, Entity casterEntity, Entity targetEntity,
                          Environment environment,
                          CollectionOfInteractions modifierInteractionCollection) : base(mi, casterEntity, targetEntity, environment, modifierInteractionCollection)
        {
            this.environment = environment;
            this.info        = (IkInfo)mi;
            mapCollider      = environment.MapColliders();

            caster = casterEntity.GetComponent <SkillComponent>().Character;
            FrameAndSecondsConverter fasc = FrameAndSecondsConverter._30Fps;

            aimAt                    = 0;
            aimDuration              = fasc.FramesToSeconds(info.Config.aimDuration);
            aimLogicDuration         = fasc.FramesToSeconds(info.Config.aimLogicDuration);
            aimInterpolationDuration = fasc.FramesToSeconds(info.Config.aimInterpolationDuration);
            startupAt                = aimAt + aimDuration;
            startupDuration          = fasc.FramesToSeconds(info.Config.startupDuration);
            activeAt                 = startupAt + startupDuration;
            activeDuration           = fasc.FramesToSeconds(info.Config.activeDuration);
            recoveryAt               = activeAt + activeDuration;
            recoveryDuration         = fasc.FramesToSeconds(info.Config.recoveryDuration);
            totalDuration            = recoveryAt + recoveryDuration;
            target                   = environment.FindNearbyCharacters(
                caster, Vector3.zero, 999,
                new[] { FindingFilter.ExcludeMe, FindingFilter.ExcludeDead, FindingFilter.ExcludeAllies }
                )[0];
            fabrik = caster.GameObject().GetComponent <FABRIK>();
            IKSolverFABRIK solverFabrik = (IKSolverFABRIK)fabrik.GetIKSolver();

            ikJoint       = solverFabrik.bones[solverFabrik.bones.Length - 1].transform;
            ikJointParent = solverFabrik.bones[solverFabrik.bones.Length - 2].transform;
        }
예제 #2
0
        private void ProcessAimPhase(float dt)
        {
            if (elapsed >= aimAt && !isAim)
            {
                isAim                = true;
                fabrik.enabled       = true;
                axisDirection        = ikJoint.rotation * ikJoint.GetComponent <RotationLimit>().axis.normalized;
                intersectionPosition = CalculateIntersectionPosition(ikJoint.position, axisDirection);
                aimPivot             = mapCollider.ClampPositionToGround(intersectionPosition);
                ikPosition           = intersectionPosition;
//				fabrik.GetIKSolver().IKPosition = ikPosition;

#if UNITY_EDITOR
                gizmosIkTarget = new SphereShape(0.1f, ikPosition, Color.red, aimDuration);
                textIkTarget   = new TextShape(ikPosition, Color.red, "IK target");
                gizmosAnimationIntersection        = new SphereShape(0.1f, intersectionPosition, Color.green, aimDuration);
                textAnimationIntersection          = new TextShape(intersectionPosition, Color.green, "Animation intersection");
                gizmosClampedAnimationIntersection = new SphereShape(0.1f, intersectionPosition, Color.red, aimDuration);
                textClampedAnimationIntersection   = new TextShape(intersectionPosition, Color.red, "Clamped anim intersection");
                gizmosAimLine     = new LineShape(ikJoint.position, Color.red, 1, Vector3.up);
                gizmosAimPosition = new SphereShape(0.1f, aimPosition, Color.red, aimDuration);
                textAimPosition   = new TextShape(aimPosition, Color.red, "Target");
                textPhase         = new TextShape(caster.Position(), Color.red, "Aiming");
                GizmosDrawer.Instance.AddRequest(new DrawRequest(gizmosIkTarget, aimDuration));
                GizmosDrawer.Instance.AddRequest(new DrawRequest(textIkTarget, aimDuration));
                GizmosDrawer.Instance.AddRequest(new DrawRequest(gizmosAnimationIntersection, aimDuration));
                GizmosDrawer.Instance.AddRequest(new DrawRequest(textAnimationIntersection, aimDuration));
                GizmosDrawer.Instance.AddRequest(new DrawRequest(gizmosClampedAnimationIntersection, aimDuration));
                GizmosDrawer.Instance.AddRequest(new DrawRequest(textClampedAnimationIntersection, aimDuration));
                GizmosDrawer.Instance.AddRequest(new DrawRequest(gizmosAimLine, aimDuration));
                GizmosDrawer.Instance.AddRequest(new DrawRequest(gizmosAimPosition, aimDuration));
                GizmosDrawer.Instance.AddRequest(new DrawRequest(textAimPosition, aimDuration));
                GizmosDrawer.Instance.AddRequest(new DrawRequest(textPhase, totalDuration));
#endif
            }

            if (isAim && aimElapsed < aimInterpolationDuration)
            {
                aimElapsed += dt;
                float progress = aimElapsed / aimInterpolationDuration;
                axisDirection = (ikJoint.position - ikJointParent.position).normalized;
//				DLog.Log("OnUpdate:axisDirection: " + axisDirection.ToPreciseString());
                intersectionPosition = CalculateIntersectionPosition(ikJointParent.position, axisDirection);
                aimPivot             = mapCollider.ClampPositionToGround(intersectionPosition);
                Vector3 aimPos = mapCollider.ClampPositionToGround(target.Position()) + info.Config.offset;
                if (info.Config.clampAngle)
                {
                    aimPos = intersectionPosition;
                }
//				Vector3 direction = (aimPos - ikJoint.position).normalized;
//				intersectionPosition = CalculateIntersectionPosition(ikJoint.position, direction);
                Vector3 clampedIntersection = intersectionPosition.CloneWithNewX(Mathf.Lerp(intersectionPosition.x, aimPos.x, progress));
                Vector3 diff = clampedIntersection - ikJointParent.position;
                ikPosition = ikJointParent.position + diff.normalized *
                             ((ikJoint.position - ikJointParent.position).magnitude + 1f);
                fabrik.GetIKSolver().IKPosition = ikPosition;

#if UNITY_EDITOR
                gizmosIkTarget.SetPos(ikPosition);
                textIkTarget.SetPos(ikPosition);
                gizmosAnimationIntersection.SetPos(intersectionPosition);
                textAnimationIntersection.SetPos(intersectionPosition);
                gizmosClampedAnimationIntersection.SetPos(clampedIntersection);
                textClampedAnimationIntersection.SetPos(clampedIntersection);
                gizmosAimLine.SetPos(ikJointParent.position);
                gizmosAimLine.Length    = diff.magnitude;
                gizmosAimLine.Direction = diff;
#endif
            }
        }