Esempio n. 1
0
        public override void AnimationStateEnter()
        {
            if (CurrentAnimTag == AnimTag.FallEdge)
            {
                //  Debug.Log("Enter Fall Edge Animation");
                IgnoreLowerStates = true;
            }
            else if (InMainTagHash)
            {
                UpImpulse = MalbersTools.CleanUpVector(animal.DeltaPos, animal.Forward, animal.Right);   //Clean the Vector from Forward and Horizontal Influence

                IgnoreLowerStates = false;

                FallSpeed = new MSpeed(animal.CurrentSpeedModifier)
                {
                    name     = "FallSpeed",
                    position = animal.HorizontalSpeed,
                    animator = 1,
                    rotation = AirRotation.Value
                };

                if (debug && animal.debugStates)
                {
                    Debug.Log($"Fall Speed: <B>{FallSpeed.position.Value.ToString("F3")}</B>");
                }


                animal.UpdateDirectionSpeed = AirControl;
                animal.SetCustomSpeed(FallSpeed, true);
            }
        }
Esempio n. 2
0
        public override void OnStateMove(float deltaTime)
        {
            if (CurrentAnimTag == MainTagHash)
            {
                if (JumpPressed)
                {
                    JumpPressedMultiplier = Mathf.Lerp(JumpPressedMultiplier, InputValue ? 1 : 0, deltaTime * JumpPressedLerp);
                }

                if (!General.RootMotion)
                {
                    Vector3 ExtraJumpForce = (animal.UpVector * activeJump.HeightMultiplier);
                    animal.AdditivePosition += ExtraJumpForce * deltaTime * JumpPressedMultiplier;
                }
                else
                {
                    Vector3 RootMotionUP = MalbersTools.CleanUpVector(Anim.deltaPosition, animal.Forward, animal.Right); //Get the Up vector of the Animation

                    float UP = Vector3.Dot(RootMotionUP, animal.Up);                                                     //Check if the Jump Root Animation is going  UP;


                    if (UP > 0)
                    {
                        animal.AdditivePosition -= RootMotionUP;                                                       //Remove the default Root Motion Jump
                        animal.AdditivePosition += RootMotionUP * activeJump.HeightMultiplier * JumpPressedMultiplier; //Add the New Root Motion Jump scaled by the Height Multiplier
                    }

                    {
                        Vector3 RootMotionForward = Vector3.ProjectOnPlane(Anim.deltaPosition, animal.Up);
                        animal.AdditivePosition -= RootMotionForward;                                    //Remove the default Root Motion Jump
                        animal.AdditivePosition += RootMotionForward * activeJump.ForwardMultiplier;     //Add the New Root Motion Jump scaled by the Height Multiplier
                    }
                }
            }
        }
Esempio n. 3
0
        public override void AnimationStateEnter()
        {
            if (CurrentAnimTag == AnimTag.FallEdge)
            {
                IgnoreLowerStates = true;
            }
            else if (CurrentAnimTag == MainTagHash)
            {
                UpImpulse = MalbersTools.CleanUpVector(animal.DeltaPos, animal.Forward, animal.Right);   //Clean the Vector from Forward and Horizontal Influence

                IgnoreLowerStates = false;

                var speedMultiplier = Vector3.ProjectOnPlane(animal.Inertia, -animal.GravityDirection);


                FallSpeed = new MSpeed(animal.CurrentSpeedModifier)
                {
                    name     = "FallSpeed",
                    position = (speedMultiplier).magnitude / animal.ScaleFactor,
                    animator = 1,
                    rotation = AirRotation.Value
                };

                animal.UpdateDirectionSpeed = AirControl;
                animal.SetCustomSpeed(FallSpeed, true);
            }
        }
Esempio n. 4
0
        public override void EnterCoreAnimation()
        {
            UpImpulse = MalbersTools.CleanUpVector(animal.DeltaPos, animal.Forward, animal.Right);   //Clean the Vector from Forward and Horizontal Influence

            IgnoreLowerStates = false;

            FallSpeed = new MSpeed(animal.CurrentSpeedModifier)
            {
                name     = "FallSpeed",
                position = animal.HorizontalSpeed,
                animator = 1,
                rotation = AirRotation.Value
            };

            if (debug && animal.debugStates)
            {
                Debug.Log($"Fall Speed: <B>{FallSpeed.position.Value:F3}</B>");
            }

            animal.UpdateDirectionSpeed = AirControl; //Set the Directional Speed to be Updated depending the Air Control var IMPORTANT
            animal.SetCustomSpeed(FallSpeed, true);

            if (animal.LastState.ID <= 1 && Vector3.Dot(UpImpulse, animal.UpVector) > 0) //means it was on locomotion or idle //Remove Up Impulse
            {
                UpImpulse = Vector3.zero;
            }
        }
Esempio n. 5
0
        public override void Activate()
        {
            base.Activate();

            Inertia           = Vector3.ProjectOnPlane(animal.DeltaPos, animal.UpVector);
            UpImpulse         = MalbersTools.CleanUpVector(animal.DeltaPos, animal.Forward, animal.Right); //Clean the Vector from Forward and Horizontal Influence
            IgnoreLowerStates = true;                                                                      //Ignore Falling, Idle and Locomotion while swimming

            animal.InertiaPositionSpeed = Vector3.zero;                                                    //THIS MOTHER F!#$ER was messing with the water entering
        }
Esempio n. 6
0
        public override void AnimationStateEnter()
        {
            if (MainTagHash == CurrentAnimTag)
            {
                verticalInertia  = MalbersTools.CleanUpVector(animal.DeltaPos, animal.Forward, animal.Right);
                acceleration     = 0;
                animal.LastState = this;                                                          //IMPORTANT for Modes that changes the Last state enter

                animal.InertiaPositionSpeed = Vector3.ProjectOnPlane(animal.DeltaPos, animal.Up); //Keep the Speed from the take off
            }
        }
Esempio n. 7
0
        public void FindWaterLevel()
        {
            if (IsInWater)
            {
                var waterCol           = WaterCollider[0];
                var PivotPointDistance = waterCol.ClosestPoint(WaterUPPivot);
                WaterPivot_Dist_from_Water = (PivotPointDistance - WaterPivotPoint);
                WaterPivot_Dist_from_Water = MalbersTools.CleanUpVector(WaterPivot_Dist_from_Water, animal.Forward, animal.Right);

                PivotAboveWater = Vector3.Dot(WaterPivot_Dist_from_Water, animal.UpVector) < 0;
            }
            else
            {
                PivotAboveWater = true;
            }
        }
Esempio n. 8
0
        public void FindWaterLevel()
        {
            if (IsInWater)
            {
                var waterCol           = WaterCollider[0];
                var PivotPointDistance = waterCol.ClosestPoint(WaterUPPivot); //IMPORTANT IS NOT CLOSEST POINT ON BOUNDS THAT CAUSES ERRORS
                WaterPivot_Dist_from_Water = (PivotPointDistance - WaterPivotPoint);
                WaterPivot_Dist_from_Water = MalbersTools.CleanUpVector(WaterPivot_Dist_from_Water, animal.Forward, animal.Right);

                PivotAboveWater = Vector3.Dot(WaterPivot_Dist_from_Water, animal.UpVector) < 0;
            }
            else
            {
                PivotAboveWater = true;
            }
        }
Esempio n. 9
0
        public override void EnterCoreAnimation()
        {
            verticalInertia  = MalbersTools.CleanUpVector(animal.DeltaPos, animal.Forward, animal.Right);
            acceleration     = 0;
            animal.LastState = this;                                                                   //IMPORTANT for Modes that changes the Last state enter ?????????????????????????

            animal.InertiaPositionSpeed          = Vector3.ProjectOnPlane(animal.DeltaPos, animal.Up); //Keep the Speed from the take off
            animal.currentSpeedModifier.Vertical = 2;

            if (GlideOnly)
            {
                animal.UseSprintState = false;
                animal.Speed_Change_Lock(true);
            }

            currentFlyElapsedTime = Time.time;
        }
Esempio n. 10
0
        public override void OnStateMove(float deltaTime)
        {
            if (InMainTagHash)
            {
                if (JumpPressed)
                {
                    JumpPressHeight_Value = Mathf.Lerp(JumpPressHeight_Value, InputValue ? 1 : 0, deltaTime * JumpPressedLerp);
                }

                //if (JumpForwardPressed)
                //{
                //    JumpPressForward_Value = Mathf.Lerp(JumpPressForward_Value, animal.MovementAxisSmoothed.z > 0.01 ? 1 : 0, deltaTime * JumpPressedLerp);
                //}

                if (!General.RootMotion) //If the Jump is NOT Root Motion!!
                {
                    Vector3 ExtraJumpHeight = (animal.UpVector * activeJump.HeightMultiplier);
                    animal.AdditivePosition += ExtraJumpHeight * deltaTime * JumpPressHeight_Value;
                    //No Worry about the horizontal speed since is inherit from the last state
                }
                else //If the Jump IS Root Motion!!
                {
                    Vector3 RootMotionUP = MalbersTools.CleanUpVector(Anim.deltaPosition, animal.Forward, animal.Right);          //Get the Up vector of the Root Motion Animation

                    bool isGoingUp = Vector3.Dot(RootMotionUP, animal.Up) > 0;  //Check if the Jump Root Animation is going  UP;


                    if (isGoingUp)
                    {
                        animal.AdditivePosition -= RootMotionUP;                                                            //Remove the default Root Motion Jump
                        animal.AdditivePosition += RootMotionUP * activeJump.HeightMultiplier * JumpPressHeight_Value;      //Add the New Root Motion Jump scaled by the Height Multiplier
                    }

                    {
                        Vector3 RootMotionForward = Vector3.ProjectOnPlane(Anim.deltaPosition, animal.Up);
                        animal.AdditivePosition -= RootMotionForward;                                //Remove the default Root Motion Jump
                        animal.AdditivePosition += RootMotionForward * activeJump.ForwardMultiplier; // * JumpPressForward_Value;      //Add the New Root Motion Jump scaled by the Height Multiplier
                    }
                }
            }
        }
Esempio n. 11
0
        public override void AnimationStateEnter()
        {
            if (CurrentAnimTag == AnimTag.FallEdge)
            {
                //   Debug.Log("Enter Fall Edge Animation");
                IgnoreLowerStates = true;
            }
            else if (InMainTagHash)
            {
                //  Debug.Log("Enter Fall");

                UpImpulse = MalbersTools.CleanUpVector(animal.DeltaPos, animal.Forward, animal.Right);   //Clean the Vector from Forward and Horizontal Influence

                IgnoreLowerStates = false;

                FallSpeed = new MSpeed(animal.CurrentSpeedModifier)
                {
                    name     = "FallSpeed",
                    position = animal.HorizontalSpeed,
                    animator = 1,
                    rotation = AirRotation.Value
                };

                if (debug && animal.debugStates)
                {
                    Debug.Log($"Fall Speed: <B>{FallSpeed.position.Value.ToString("F3")}</B>");
                }


                //bool GoingUP = Vector3.Dot(animal.DeltaPos, animal.GravityDirection) < 0; //Check if is falling down
                //if (GoingUP)
                //{
                //    FallCurrentDistance =  -UpImpulse.magnitude/animal.DeltaTime + (animal.GravityForce * animal.GravityMultiplier * animal.DeltaTime);
                //    animal.SetFloatID(FallCurrentDistance);
                //}

                animal.UpdateDirectionSpeed = AirControl;
                animal.SetCustomSpeed(FallSpeed, true);
            }
        }
Esempio n. 12
0
        public override void AnimationStateEnter()
        {
            if (CurrentAnimTag == AnimTag.FallEdge)
            {
                IgnoreLowerStates = true;
            }
            else if (CurrentAnimTag == MainTagHash)
            {
                UpImpulse = MalbersTools.CleanUpVector(animal.DeltaPos, animal.Forward, animal.Right);   //Clean the Vector from Forward and Horizontal Influence

                IgnoreLowerStates = false;

                FallSpeed = new MSpeed(animal.CurrentSpeedModifier)
                {
                    name     = "FallSpeed",
                    position = animal.HorizontalSpeed,
                    animator = 1,
                    rotation = AirRotation.Value
                };

                animal.UpdateDirectionSpeed = AirControl;
                animal.SetCustomSpeed(FallSpeed, true);
            }
        }
Esempio n. 13
0
        public override void TryExitState(float DeltaTime)
        {
            // Debug.Log("Try Exit Fall");

            bool GoingDown = Vector3.Dot(animal.DeltaPos, animal.GravityDirection) > 0; //Check if is falling down

            if (GoingDown)
            {
                FallCurrentDistance += Vector3.Project(animal.DeltaPos, animal.GravityDirection).magnitude;
            }


            FallPoint = animal.Main_Pivot_Point + animal.AdditivePosition;

            if (animal.debugGizmos && debug)
            {
                // MalbersTools.DebugTriangle(animal.Main_Pivot_Point, animal.RayCastRadius * animal.ScaleFactor, Color.magenta);
                MalbersTools.DebugTriangle(FallPoint, animal.RayCastRadius * animal.ScaleFactor, Color.magenta);
                Debug.DrawRay(FallPoint, animal.GravityDirection * 100f, Color.magenta);
            }

            //int hits = Physics.SphereCastNonAlloc(FallPoint, animal.RayCastRadius * animal.ScaleFactor,animal.GravityDirection, FallHits, 100f, animal.GroundLayer, QueryTriggerInteraction.Ignore);
            //if (hits > 0)
            if (Physics.SphereCast(FallPoint, animal.RayCastRadius, animal.GravityDirection, out FallRayCast, 100f, animal.GroundLayer, QueryTriggerInteraction.Ignore))
            {
                DistanceToGround = FallRayCast.distance - (/*animal.AdditivePosition.magnitude +*/ animal.DeltaPos.magnitude);

                if (animal.debugGizmos && debug)
                {
                    MalbersTools.DebugTriangle(FallRayCast.point, animal.RayCastRadius * animal.ScaleFactor, Color.magenta);
                }


                switch (BlendFall)
                {
                case FallBlending.DistanceNormalized:
                {
                    if (MaxHeight < DistanceToGround)
                    {
                        MaxHeight = DistanceToGround;                                                                                              //get the Highest Distance the first time you touch the ground
                    }
                    FallBlend = Mathf.Lerp(FallBlend, (DistanceToGround - LowerBlendDistance) / (MaxHeight - LowerBlendDistance), DeltaTime * 20); //Small blend in case there's a new ground found
                    animal.SetFloatID(FallBlend);                                                                                                  //Blend between High and Low Fall
                }
                break;

                case FallBlending.Distance:
                    animal.SetFloatID(FallCurrentDistance);
                    break;

                case FallBlending.VerticalVelocity:

                    var UpInertia = MalbersTools.CleanUpVector(animal.DeltaPos, animal.Forward, animal.Right).magnitude;       //Clean the Vector from Forward and Horizontal Influence

                    animal.SetFloatID(UpInertia / animal.DeltaTime * (GoingDown?1:-1));
                    break;

                default:
                    break;
                }

                //Debug.Log(DistanceToGround);

                if (animal.Height >= DistanceToGround)
                {
                    var TerrainSlope = Vector3.Angle(FallRayCast.normal, animal.UpVector);
                    var DeepSlope    = TerrainSlope > animal.maxAngleSlope;

                    if (!DeepSlope)
                    {
                        animal.AlingRayCasting(); //Check one time the Align Rays to calculate the Angle Slope used on the CanFallOnSlope
                        AllowExit();
                        animal.Grounded   = true; //This Allow Locomotion and Idle to Try Activate themselves
                        animal.UseGravity = false;
                    }
                }
            }
        }