Ejemplo n.º 1
0
        Vector3 GetAIMDirection()
        {
            Vector3 TargetDir;

            if (ForcedTarget)
            {
                TargetDir          = MalbersTools.DirectionTarget(AimOrigin, ForcedTarget);
                AimRayTargetAssist = !Limited ? ForcedTarget : null;
                AimPoint           = ForcedTarget.position;
            }
            else
            {
                GetCenterScreen();
                DirectionFromCamera(ScreenCenter, out aimHit, IgnoreTransform);
                AimPoint = AimHit.point;

                TargetDir = (AimPoint - AimOrigin.position);
            }

            return(TargetDir);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Rotates the bones to the Look direction (Only works when the animator is set to Update Mode : Normal)
        /// </summary>
        void LookAtBoneSet()
        {
            hasTarget = false;
            if (UseCamera || Target)
            {
                hasTarget = true;
            }


            angle = Vector3.Angle(transform.forward, direction);                                                    //Find the angle for the current bone


            currentSmoothness = Mathf.Lerp(currentSmoothness, IsAiming ? 1 : 0, Time.deltaTime * Smoothness);

            if (currentSmoothness > 0.999f)
            {
                currentSmoothness = 1;
            }
            if (currentSmoothness < 0.001f)
            {
                currentSmoothness = 0;
            }



            foreach (var bone in Bones)
            {
                if (!bone.bone)
                {
                    continue;
                }

                Vector3 dir = transform.forward;


                if (UseCamera)
                {
                    dir = cam.forward;

                    aimHit = MalbersTools.RayCastHitToCenter(bone.bone);

                    if (aimHit.collider)
                    {
                        dir = MalbersTools.DirectionTarget(bone.bone.position, aimHit.point);
                    }
                }

                if (Target)
                {
                    dir = MalbersTools.DirectionTarget(bone.bone, Target);
                }

                direction = Vector3.Lerp(direction, dir, Time.deltaTime * Smoothness);

                if (currentSmoothness == 0)
                {
                    return;                                                                 //Skip all next stuffs
                }
                if (debug)
                {
                    Debug.DrawRay(bone.bone.position, direction * 15, Color.green);
                }


                var final = Quaternion.LookRotation(direction, UpVector) * Quaternion.Euler(bone.offset);
                var next  = Quaternion.Lerp(bone.bone.rotation, final, bone.weight * currentSmoothness);
                bone.bone.rotation = next;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Rotates the bones to the Look direction (Unfortunately with no Lerp between them
        /// </summary>
        void LookAtBoneSet_AnimatePhysics()
        {
            hasTarget = false;
            if (UseCamera || Target)
            {
                hasTarget = true;
            }


            angle = Vector3.Angle(transform.forward, direction);


            foreach (var bone in Bones)
            {
                if (!bone.bone)
                {
                    continue;
                }

                Vector3 dir = transform.forward;

                if (UseCamera)
                {
                    dir = cam.forward;

                    aimHit = MalbersTools.RayCastHitToCenter(bone.bone);

                    if (aimHit.collider)
                    {
                        dir = MalbersTools.DirectionTarget(bone.bone.position, aimHit.point);
                    }
                }
                if (Target)
                {
                    dir = (Target.position - bone.bone.position).normalized;
                }

                direction = Vector3.Lerp(direction, dir, Time.deltaTime * Smoothness);



                angle = Vector3.Angle(transform.forward, direction); //Set the angle for the current bone

                if ((angle < LimitAngle && active && hasTarget))
                {
                    var final = Quaternion.LookRotation(direction, Vector3.up) * Quaternion.Euler(bone.offset);
                    var next  = Quaternion.Lerp(bone.initialRotation, final, bone.weight);
                    bone.initialRotation = Quaternion.Lerp(bone.initialRotation, next, Time.deltaTime * Smoothness * 2);
                    moreRestore          = 1;
                    if (debug)
                    {
                        Debug.DrawRay(bone.bone.position, direction * 5, Color.green);
                    }
                }
                else
                {
                    moreRestore         += Time.deltaTime;
                    bone.initialRotation = Quaternion.Lerp(bone.initialRotation, bone.bone.rotation, Time.deltaTime * Smoothness * 2 * moreRestore);

                    moreRestore = Mathf.Clamp(moreRestore, 0, 1000); //this is for not making bigger than 1000
                }
                bone.bone.rotation = bone.initialRotation;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Rotates the bones to the Look direction (Only works when the animator is set to Update Mode : Normal)
        /// </summary>
        void LookAtBoneSet()
        {
            if (!Target && !cam)
            {
                return;                  //If there's no camera and no Target ignore completely
            }
            hasTarget = false;
            if (UseCamera || Target)
            {
                hasTarget = true;
            }


            angle = Vector3.Angle(transform.forward, direction);                                                    //Find the angle for the current bone


            currentSmoothness = Mathf.Lerp(currentSmoothness, IsAiming ? 1 : 0, Time.deltaTime * Smoothness);

            if (currentSmoothness > 0.9999f)
            {
                currentSmoothness = 1;
            }
            if (currentSmoothness < 0.0001f)
            {
                currentSmoothness = 0;
            }

            for (int i = 0; i < Bones.Length; i++)
            {
                var bone = Bones[i];

                if (!bone.bone)
                {
                    continue;               //if There's no bone skip
                }
                Vector3 dir = transform.forward;


                if (UseCamera && cam)
                {
                    dir = cam.forward;

                    aimHit = MalbersTools.RayCastHitToCenter(bone.bone, ~Ignore); //Calculate the Direction from the Bone

                    if (aimHit.collider)                                          //if something was hit
                    {
                        dir = MalbersTools.DirectionTarget(bone.bone.position, aimHit.point);
                    }
                }

                if (Target)
                {
                    dir = MalbersTools.DirectionTarget(bone.bone, Target);
                }



                direction = Vector3.Lerp(direction, dir, Time.deltaTime * Smoothness);

                if (currentSmoothness == 0)
                {
                    return;                                                                 //Skip all next stuffs
                }
                if (debug && i == Bones.Length - 1)
                {
                    Debug.DrawRay(bone.bone.position, direction * 15, Color.green);
                }


                var final = Quaternion.LookRotation(direction, UpVector) * Quaternion.Euler(bone.offset);
                var next  = Quaternion.Lerp(bone.bone.rotation, final, bone.weight * currentSmoothness);
                bone.bone.rotation = next;
            }
        }