Exemplo n.º 1
0
        //bool rotateBasedOnCamera = false;
        void Rotate(StateManager sm)
        {
            if (cameraTransform.value == null)
            {
                return;
            }
            //keep track fo previous rotation in case we need to revert back to it, in the the case of detecting an unclimbable surface
            prevRotation = states.mTransform.rotation;
            float h = states.movementVariables.horizontal;
            float v = states.movementVariables.vertical;

            //Get the angle between the camera's forward and the climb's up and get it in 360 degrees
            Vector3 camForward = cameraTransform.value.forward;
            Vector3 camRight   = cameraTransform.value.right;

            camForward.y = 0;
            camForward.Normalize();
            camRight.y = 0;
            camRight.Normalize();

            float rotateAngle = -Vector3.Angle(climbUp, camForward);

            rotateAngle = (Vector3.Angle(climbRight, camForward) > 90f) ? 360f - rotateAngle : rotateAngle;

            //rotating climb up and climb right based on camera's position
            Vector3 climbForwardAlt = climbForward;
            Vector3 climbRightAlt   = climbRight;

            //float sAngle = Vector3.SignedAngle(climbRight, camForward, Vector3.up);
            //climbRightAlt = (sAngle <= 45f || sAngle >= 135f) ? climbRight : - climbRight;
            //Debug.Log("ANGLE: " + Vector3.Angle(climbRight, camForward) + " || SIGNED ANGLE: " + Vector3.SignedAngle(climbRight, camForward, Vector3.up));

            //if (rotateBasedOnCamera)
            //{
            //    climbForwardAlt = (Quaternion.AngleAxis(rotateAngle, climbUp) * -climbForward);
            //    climbRightAlt = (Quaternion.AngleAxis(rotateAngle, climbUp) * -climbRight);
            //    if(climbForwardAlt == Vector3.zero)
            //        climbForwardAlt = climbForward;
            //    if (climbRightAlt == Vector3.zero)
            //        climbRightAlt = climbRight;
            //}

            //Debug.DrawRay(states.mTransform.position, climbForwardAlt * 5f, Color.magenta);
            //Debug.DrawRay(states.mTransform.position, climbRightAlt * 5f, Color.cyan);

            Vector3 targetDir = climbForwardAlt * v;

            targetDir += (climbRightAlt * h);
            targetDir.Normalize();
            //Debug.DrawRay(states.transform.position, targetDir * 5, Color.magenta);
            //Debug purposes to visualize the direction
            //Debug.DrawRay(states.transform.position, climbForwardAlt * 3, Color.red);
            //Debug.DrawRay(states.transform.position, climbRightAlt * 3, Color.yellow);

            //If there's no input, then don't do anything
            if (targetDir == Vector3.zero)
            {
                return;
            }

            //Apply rotation
            states.movementVariables.moveDirection = targetDir;
            //rotationSpeed = Mathf.Lerp(20, 6, (states.rigid.velocity.magnitude / 6f));
            Quaternion tr = Quaternion.LookRotation(targetDir, states.transform.up);

            tRotation = Quaternion.Slerp(states.mTransform.rotation, tr, Time.deltaTime * states.movementVariables.moveAmount * states.climbingVariables.turnSpeed);
            //Quaternion targetRotation = Quaternion.Slerp(states.mTransform.rotation, tr, states.delta * states.movementVariables.moveAmount * rotationSpeed);

            //Vector3 underOrigin = states.transform.position;
            //underOrigin += (targetRotation * Vector3.forward)  + (states.transform.up * 0.5f);

            //// Dir represents the downward direction
            //Vector3 dir = (states.transform.position + states.transform.forward + (-states.transform.up * 1.5f)) - underOrigin;
            //RaycastHit hit = new RaycastHit();
            //Debug.DrawRay(underOrigin, dir, Color.magenta);
            //if (Physics.Raycast(underOrigin, dir.normalized, out hit, 1.5f, Layers.ignoreLayersController, QueryTriggerInteraction.Ignore))
            //{
            //    if (hit.transform.tag == "Climb")
            //        states.mTransform.rotation = targetRotation;
            //}
        }
Exemplo n.º 2
0
 public override void Execute(StateManager sm)
 {
 }
Exemplo n.º 3
0
        void CheckRaycast(StateManager sm)
        {
            float   topFloat    = .4f;
            Vector3 frontOrigin = states.transform.position + (states.transform.forward * 1.5f) + (states.transform.up * topFloat);

            //Debug.DrawRay(frontOrigin, states.transform.forward * 0.75f, Color.blue);
            //Raycast in front of the squirrel, used to check if we've hit a ceiling, ground, or another climb-able surface
            if (Physics.Raycast(frontOrigin, states.transform.forward, out front, 0.75f, Layers.ignoreLayersController, QueryTriggerInteraction.Ignore))
            {
                frontHit = true;
                float angle = Vector3.Angle(front.normal, Vector3.up);
                //front has hit a new climb that means the change is a big one, no need to check the angle
                if (front.transform.tag == "Climb")
                {
                    ignoreGravity         = true;
                    prevAngle             = Vector3.Angle(front.normal, states.climbHit.normal);
                    states.rigid.velocity = Vector3.zero;
                    //Debug.Log("Front are you f*****g things up, do I have to fix you?");

                    //SetCameraAngle(states.climbHit.normal, -front.normal);

                    states.climbHit = front;
                    startPos        = states.transform.position;
                    targetPos       = states.climbHit.point + (states.climbHit.normal * states.climbingVariables.offsetFromWall);
                    targetRot       = Quaternion.FromToRotation(states.transform.up, states.climbHit.normal) * states.transform.rotation;
                    tVelocity       = Vector3.zero;
                    tRotation       = targetRot;
                    t     = 0;
                    inPos = false;
                    inRot = false;

                    transitioning = true;
                    safeTurn      = true;
                    //Debug.Log("Transitiong");
                    lagDashCooldown = states.lagDashCooldown;

                    // 9/2/20: Acute corner transfer best value - 1.15f
                    // Animation speed - .75f
                    states.climbingVariables.transferSpeedMult = 1.15f;
                    states.anim.CrossFade(states.hashes.squ_climb_corner_acute, 0.2f);
                    SafeClimb();
                    return;
                }
                else
                {
                    if (angle < 70)
                    {
                        //Debug.LogError("Front has detected non-climbable surface, exit the climb");
                        states.rigid.velocity = Vector3.zero;
                        states.climbHit       = front;
                        states.anim.CrossFade(states.hashes.squ_climb_corner_acute, 0.2f);
                        states.climbState = PlayerManager.ClimbState.EXITING;
                        states.climbingVariables.transferSpeedMult = 1.5f;
                        return;
                    }
                    else
                    {
                        //Debug.Log("Front has detected a wall that blocks the user and isn't climbable");
                        states.rigid.velocity = Vector3.zero;
                    }
                }
            }
            else
            {
                frontHit = false;
            }


            Vector3 underOrigin = states.transform.position;

            underOrigin += states.transform.forward * 1.7f + (states.transform.up * 0.5f);

            // Dir represents the downward direction
            Vector3 dir = -states.transform.forward + (-states.transform.up);

            // Draw the rays
            //Debug.DrawRay(underOrigin, dir * 1.5f, Color.green);
            //Debug.DrawRay(underOrigin, Quaternion.AngleAxis(30f, states.climbHit.normal) * dir * 1.5f, Color.red);
            //Debug.DrawRay(underOrigin, Quaternion.AngleAxis(-30f, states.climbHit.normal) * dir * 1.5f, Color.blue);
            if (Physics.Raycast(underOrigin, dir, out under, 1.5f, Layers.ignoreLayersController, QueryTriggerInteraction.Ignore))
            {
                //underside has hit something
                underHit = true;
                float angle = Vector3.Angle(under.normal, Vector3.up);
                //If I hit another climb, check if I should transfer to it
                if (under.transform.tag == "Climb")
                {
                    UnderHit();
                }
                //I didn't hit a climb but I must do something based on the angle of the hit
                else
                {
                    //detach
                    if (angle < 70)
                    {
                        //Debug.LogError("Under has detected non-climbable surface, exit the climb");
                        states.climbHit   = under;
                        states.climbState = PlayerManager.ClimbState.EXITING;

                        states.anim.CrossFade(states.hashes.squ_climb_corner, 0.2f);
                        states.anim.SetBool(states.hashes.isClimbing, false);
                        states.rigid.velocity = Vector3.zero;
                        states.climbingVariables.transferSpeedMult = 1.5f;
                        return;
                    }
                    ////detach
                    //else if (angle > 90)
                    //{
                    //    Debug.Log("Under has detected a wall that blocks the user and isn't climbable");
                    //    states.climbState = PlayerManager.ClimbState.NONE;
                    //    states.isJumping = true;
                    //    states.anim.SetBool(states.hashes.isClimbing, false);
                    //    return;
                    //}
                    //stop moving
                    else
                    {
                        //Debug.Log("Under has detected a non-climbable surface, stop moving");
                        //states.rigid.velocity = -states.rigid.velocity;
                        //states.rigid.velocity = Vector3.zero;
                        //states.transform.rotation = prevRotation;
                        return;
                    }
                }
            }
            else
            {
                if (Physics.Raycast(underOrigin, Quaternion.AngleAxis(30f, states.climbHit.normal) * dir, out under, 1.5f, Layers.ignoreLayersController, QueryTriggerInteraction.Ignore))
                {
                    if (under.transform.tag == "Climb")
                    {
                        UnderHit();
                    }
                }
                else if (Physics.Raycast(underOrigin, Quaternion.AngleAxis(-30f, states.climbHit.normal) * dir, out under, 1.5f, Layers.ignoreLayersController, QueryTriggerInteraction.Ignore))
                {
                    if (under.transform.tag == "Climb")
                    {
                        UnderHit();
                    }
                }
                else
                {
                    underHit = false;
                    states.rigid.velocity = Vector3.zero;
                    //Debug.LogError("Under isn't hitting anything");
                    states.climbState = PlayerManager.ClimbState.NONE;
                    states.isJumping  = true;
                    states.anim.SetBool(states.hashes.isClimbing, false);
                }
            }
        }
Exemplo n.º 4
0
 public void Set(StateManager s)
 {
     value = s;
 }
Exemplo n.º 5
0
        public override bool CheckCondition(StateManager sm)
        {
            PlayerManager state = (PlayerManager)sm;

            return(state.climbState == PlayerManager.ClimbState.EXITING);
        }
Exemplo n.º 6
0
        public override bool CheckCondition(StateManager sm)
        {
            PlayerManager state = (PlayerManager)sm;

            return(!state.newDashActive && state.isGrounded);
        }
Exemplo n.º 7
0
        public override bool CheckCondition(StateManager sm)
        {
            EnemyManager state = (EnemyManager)sm;

            return(state.state == EnemyManager.DetectState.DETECTED);
        }
Exemplo n.º 8
0
        public override bool CheckCondition(StateManager sm)
        {
            PlayerManager state = (PlayerManager)sm;

            return(!state.dashActive && state.climbState != PlayerManager.ClimbState.NONE);
        }
Exemplo n.º 9
0
        public override void Execute(StateManager sm)
        {
            PlayerManager states = (PlayerManager)sm;

            ground = states.GetRotationNormal();
            //Vector3 origin = states.transform.position + (states.transform.up * 0.2f) + (states.transform.forward * 1.75f);
            //RaycastHit hit = new RaycastHit();
            //Vector3 dir = SlidePlayer.ProjectVectorOnPlane(Vector3.up, states.transform.forward);
            //Debug.DrawRay(origin, dir * 0.5f, Color.blue);
            ////Raycast in front of the squirrel, used to check if we've hit a ceiling, ground, or another climb-able surface
            //if (Physics.SphereCast(origin, 0.2f, states.transform.forward, out hit, 0.5f, Layers.ignoreLayersController, QueryTriggerInteraction.Ignore))
            //{
            //    ground = (hit.normal + ground).normalized;
            //    Debug.DrawRay(hit.point, hit.normal, Color.black);
            //}
            ////If the front raycast hasn't hit anything then do another raycast
            ////Otherwise just use the front normal
            //if (states.front == null)
            //{
            //    //This raycast goes out the back and points diagonally behnd the player
            //    //If this hits something then use that as the ground unless it hit a wall
            //    Vector3 origin = states.transform.position;
            //    origin += states.transform.up * 0.35f;
            //    RaycastHit hit;
            //    bool didHit;
            //    Vector3 dir = -states.transform.forward - states.transform.up;
            //    Debug.DrawRay(origin, dir * 0.6f, Color.green);
            //    didHit = Physics.Raycast(origin, dir, out hit, 0.6f, Layers.ignoreLayersController, QueryTriggerInteraction.Ignore);

            //    if (didHit)
            //    {
            //        float backAngle = Vector3.Angle(hit.normal, Vector3.up);
            //        if (backAngle >= 70)
            //            didHit = false;
            //        else
            //            ground = hit.normal;
            //    }

            //    if (!didHit)
            //    {
            //        ground = states.groundNormal;
            //    }
            //}
            //else
            //    ground = states.frontNormal;

            float angle = Vector3.Angle(ground, Vector3.up);

            float angle2 = Vector3.Angle(states.mTransform.up, Vector3.up);
            //Debug.Log("angle 2 - " + angle2);


            // QUATERNION WAY

            float amount = 15;

            var test = states.GetComponent <Animation>();

            if (states.rotateFast && !states.anim.GetBool(states.hashes.isLanding))
            {
                bool quickLand = states.anim.GetBool(states.hashes.QuickLand);

                if (!quickLand)
                {
                    amount = 30;
                }
                //else
                //    amount = 15;
            }

            if (angle < rotationConstraint)
            {
                Quaternion tr             = Quaternion.FromToRotation(states.mTransform.up, ground) * states.mTransform.rotation;
                Quaternion targetRotation = Quaternion.Slerp(states.mTransform.rotation, tr, states.delta * amount);
                states.mTransform.rotation = targetRotation;
            }

            if (Mathf.Abs((angle2 - angle)) < 1.0f)
            {
                states.anim.SetBool(states.hashes.QuickLand, false);
            }

            // NON-Quaternion way

            /*Vector3 newAxis = Vector3.Cross(states.mTransform.up, states.groundNormal);
             * float angle3 = Vector3.Angle(states.mTransform.up, states.groundNormal);
             * states.mTransform.RotateAround(states.mTransform.position, newAxis, angle3);*/
        }
Exemplo n.º 10
0
        public override void Execute(StateManager sm)
        {
            PlayerManager states = (PlayerManager)sm;

            states.anim.SetBool(states.hashes.waitForAnimation, status);
        }
Exemplo n.º 11
0
        public override bool CheckCondition(StateManager sm)
        {
            PlayerManager state = (PlayerManager)sm;

            // get ammt of time since jump/leaving ground
            float timeDifference = Time.realtimeSinceStartup - state.timeSinceJump;

            /*if (state.isGrounded)
             *  Debug.Log(timeDifference);*/

            // have to have been ungrounded to start checking
            if (timeDifference > .35f)
            {
                bool result = state.isGrounded;

                /*bool test2 = state.anim.GetBool(state.hashes.inDaFall);
                 *
                 * bool result = false;
                 *
                 * if (test && !test2)
                 *  result = true;*/

                // if grounded, then land
                if (result)
                {
                    bool inMeat = false;

                    if (state.front != null)
                    {
                        inMeat = (state.front.name == "BenchMeat");
                    }
                    if (state.middle != null)
                    {
                        inMeat = (state.middle.name == "BenchMeat");
                    }
                    if (state.back != null)
                    {
                        inMeat = (state.back.name == "BenchMeat");
                    }

                    //If been in air for at least a certain amt of time, do the long land anim
                    if (timeDifference > .65f && !inMeat)
                    {
                        state.anim.CrossFade(state.hashes.Land, .2f);
                        Debug.Log("Landing with the land animation!");
                    }

                    //If not, quick land
                    else
                    {
                        state.anim.SetBool(state.hashes.QuickLand, true);
                    }
                }

                return(result);
            }

            else
            {
                return(false);
            }
        }
Exemplo n.º 12
0
        public override void Execute(StateManager sm)
        {
            PlayerManager states = (PlayerManager)sm;

            float      frontY = 0;
            RaycastHit hit;
            RaycastHit hit2;
            Vector3    origin  = states.mTransform.position + (states.mTransform.forward * frontRayOffset);
            Vector3    origin2 = states.mTransform.position;

            origin.y  += .5f;
            origin2.y += .5f;

            Vector3 testOrigin = states.mTransform.position + (states.mTransform.forward * .75f);

            testOrigin.y += .5f;
            RaycastHit testHit;

            //Debug.DrawRay(origin2, -Vector3.up, Color.red);
            Vector3 targetVelocity = states.mTransform.forward * states.movementVariables.moveAmount * movementSpeed * states.groundSpeedMult;

            Vector3 dir = -Vector3.up;

            // If player is on a sloped surface, must account for the normal
            dir.z = dir.z - states.groundNormal.z;

            //Debug.DrawRay(origin, dir, Color.red);
            //Debug.DrawRay(origin2, dir, Color.cyan);

            // Raycast from first origin point
            if (Physics.Raycast(origin, dir, out hit, 1, Layers.ignoreLayersController, QueryTriggerInteraction.Ignore))
            {
                // Store y position of hit point
                float y = hit.point.y;

                // Set StateManager ground normal to be normal of hit
                if (Vector3.Angle(hit.normal, Vector3.up) <= 35)
                {
                    states.groundNormal       = hit.normal;
                    states.backupGroundNormal = hit.normal;
                }
                else
                {
                    states.backupGroundNormal = hit.normal;
                }

                if (Physics.Raycast(testOrigin, dir, out testHit, 1, Layers.ignoreLayersController, QueryTriggerInteraction.Ignore))
                {
                }

                // Set frontY to hit point y pos - player's y pos
                //WHY?
                frontY = y - states.mTransform.position.y;

                // Second Raycast from second origin point
                if (Physics.Raycast(origin2, dir, out hit2, 1, Layers.ignoreLayersController, QueryTriggerInteraction.Ignore))
                {
                    // If front hit is on a different ground than second hit, most likeley moving between two different grounds
                    // If so, shouldn't rotate quickly
                    if (hit.normal != hit2.normal)
                    {
                        states.rotateFast = false;
                    }
                    else
                    {
                        states.rotateFast = true;
                    }
                }

                // Trying to address the problem of player "landing" too high up, and then slowly sinking into the slope

                //Debug.Log("hit 1 distance - " + hit.distance);
                //Debug.Log("hit 2 distance - " + hit2.distance);

                // If either of the two raycast hits are too far down
                if (hit.distance > .54f || hit2.distance > .54f)
                {
                    //targetVelocity.y -= 45f;

                    // Set player's position slighly down and then move towards it
                    var test = states.rigid.position;
                    test.y -= .05f;
                    states.rigid.MovePosition(test);
                }
            }

            Vector3 currentVelocity = states.rigid.velocity;

            // If grounded
            if (states.isGrounded)
            {
                // Get move amount from movement variables
                float moveAmount = states.movementVariables.moveAmount;

                // If at least 0.1f movement
                if (moveAmount > 0.1f)
                {
                    // Set drag to 0 while moving
                    states.rigid.drag = 0;

                    // If player is on a slope
                    if (Mathf.Abs(frontY) > 0.02f)
                    {
                        //targetVelocity.y = ((frontY > 0) ? 1 : -1) * movementSpeed;
                        //targetVelocity.y = frontY * movementSpeed;

                        // Set y for target vel
                        // If frontY is positive (upward slope) then add .2f to the velocity
                        // If frontY is negative (downward slope) then don't do anything
                        //targetVelocity.y = ((frontY > 0) ? frontY + 0.2f : frontY) * movementSpeed;

                        //// If targetVelocity.y is greater than 0, then set it to 0
                        //// TODO: These two sections seem to cancel each other out
                        //// This cancels out the extra jump you could get off of slopes
                        //if (targetVelocity.y > 0)
                        //{
                        //    targetVelocity.y = 0;
                        //}
                    }
                }

                // If not moving at least 0.1f
                else
                {
                    // Get abs of frontY
                    float abs = Mathf.Abs(frontY);

                    // If player is on any slope
                    if (abs > 0.02f && states.slideMomentum.magnitude < 0.25f)
                    {
                        //states.rigid.isKinematic = false;

                        // Stop moving and increase drag so that player doesn't slide while idling
                        // TODO: check what lower drag values work instead of 4000. Probably is too high.
                        //targetVelocity.y = 0;
                        states.rigid.drag = 4000;
                    }
                }
            }
            else
            {
                states.rigid.isKinematic = false;
                states.rigid.drag        = 0;
                targetVelocity.y         = currentVelocity.y;
            }

            #region Step up stuff

            // If step up is true
            // Right now, moves y position up slightly
            if (states.stepUp)
            {
                bool positive = false;

                var test = states.rigid.position;

                //var test = states.mTransform.forward.z;
                if (test.z > 0)
                {
                    positive = true;
                }
                //Debug.Log(states.mTransform.forward.z);

                /*if (positive)
                 *   test.z += .2f;
                 * else
                 *   test.z -= -.2f;*/
                test.y = test.y + .25f;
                states.rigid.position = Vector3.Lerp(states.rigid.position, test + (states.mTransform.forward / 4), states.delta * 10);
                //states.rigid.velocity = new Vector3(states.rigid.velocity.x, 0, states.rigid.velocity.z);
                //targetVelocity.y += 1f;
                //states.rigid.AddRelativeForce(0, 10f, 0);
                //targetVelocity.y += 1;
                //holdYVel = targetVelocity.y;
            }

            // Step up Jump testing
            if (states.stepUpJump)
            {
                bool positive = false;

                var test = states.rigid.position;

                //var test = states.mTransform.forward.z;
                if (test.z > 0)
                {
                    positive = true;
                }
                //Debug.Log(states.mTransform.forward.z);

                /*if (positive)
                 *   test.z += .2f;
                 * else
                 *   test.z -= -.1f;*/
                test.y = test.y + .1f;
                //states.rigid.position = Vector3.Lerp(states.rigid.position, test, states.delta * 20);
                //targetVelocity.y += 1f;
                //states.rigid.AddRelativeForce(0, 10f, 0);
                //targetVelocity.y += 1;
                //holdYVel = targetVelocity.y;
            }
            #endregion

            //(Just for moving quickly in Debug - NOT how it will be done later in game)
            //if (states.isRun)
            //{
            //    targetVelocity = targetVelocity * 5;
            //}


            states.targetVelocity = targetVelocity;
            states.rigid.velocity = Vector3.Lerp(currentVelocity, targetVelocity + states.slideMomentum, states.delta * movementTime);
            //Debug.Log(states.rigid.velocity);
        }