Exemplo n.º 1
0
        public void grindSetup()
        {
            behindVector = -(states.facingPoint - states.behindPoint).normalized;
            Vector3 testFront = states.mTransform.position + (states.mTransform.forward * 2);

            Vector3 frontClosest = GetPoint(testFront, states.facingPoint, states.behindPoint);
            Vector3 backClosest  = GetPoint(states.mTransform.position, states.facingPoint, states.behindPoint);

            if (Vector3.Distance(frontClosest, testFront) < Vector3.Distance(backClosest, states.mTransform.position))
            {
                backClosest = frontClosest + (behindVector * 2f);
            }
            else
            {
                frontClosest = backClosest - (behindVector * 2f);
            }

            //Vector3 frontClosest = GetPoint(testFront, states.facingPoint, states.behindPoint);

            RaycastHit hit = new RaycastHit();

            optimalPoint = backClosest;

            Vector3 projectedVector = SlidePlayer.ProjectVectorOnPlane(-behindVector, Vector3.up);

            if (Physics.Raycast(frontClosest + (projectedVector * 0.2f), behindVector, out hit, 2f, Layers.ignoreLayersController, QueryTriggerInteraction.Ignore))
            {
                Debug.Log("Front to back hit");
                optimalPoint = backClosest - (behindVector * (2f - hit.distance));
            }
            else if (Physics.Raycast(backClosest + (projectedVector * 0.2f), -behindVector, out hit, 2f, Layers.ignoreLayersController, QueryTriggerInteraction.Ignore))
            {
                Debug.Log("back to front hit");
                optimalPoint = backClosest + (-behindVector * (2f - hit.distance));
            }

            //var end0 = states.grindEnds[0];

            /*if (Physics.Raycast(testFront, optimalPoint, out hit, 2f, Layers.ignoreLayersController, QueryTriggerInteraction.Ignore))
             * {
             *  Debug.Log(hit.collider.tag);
             * }*/

            //if (states.facingPoint == states.grindPoints[0])
            //{
            //Debug.Log("optimalPoint - " + Vector3.Distance(optimalPoint, states.facingPoint));
            //Debug.Log("end0 - " + Vector3.Distance(end0, states.facingPoint));

            //if (Vector3.Distance(optimalPoint, states.facingPoint) < Vector3.Distance(end0, states.facingPoint))
            //{
            //states.LeaveGrindOverride();

            /*var holdFacing = states.facingPoint;
             * var holdFacingPair = states.facingPointPair;
             * states.facingPoint = states.behindPoint;
             * states.facingPointPair = states.behindPointPair;
             * states.behindPoint = holdFacing;
             * states.behindPointPair = holdFacingPair;*/


            //states.LeftUndergroundGrind();


            // Debug.Log("fruit swapping");
            //}

            //Debug.Log("ya facing the end");
            //}

            /*Debug.Log("opt = " + optimalPoint + " AND grind end = " + states.grindEnds[0]);
             * Debug.Log("something's amiss - " + (states.grindEnds[0].y - optimalPoint.y));
             *
             * if (optimalPoint.y < states.grindEnds[0].y)
             * {
             *  OnExit(states);
             * }*/

            //states.frontCollider.enabled = false;
            adjusting = true;
        }
Exemplo n.º 2
0
        public override void Execute(StateManager sm)
        {
            PlayerManager states = (PlayerManager)sm;

            if (cameraTransform.value == null)
            {
                return;
            }

            var test = cameraTransform.value;
            //test.forward = states.mTransform.forward;

            float h = states.movementVariables.horizontal;
            float v = states.movementVariables.vertical;

            Vector3 targetDir = test.forward * v;

            targetDir += test.right * h;

            var targetDir2 = targetDir;

            targetDir.Normalize();
            targetDir.y = 0;

            if (targetDir == Vector3.zero)
            {
                targetDir = states.mTransform.forward;
            }

            states.movementVariables.moveDirection = targetDir;

            var targetDir3 = targetDir;

            targetDir3.y = -states.mTransform.forward.y;

            targetDir2.y = -states.mTransform.forward.y;

            // Debug.Log("targetDir2 - " + targetDir2);

            Vector3 rotationNormal = states.GetRotationNormal();

            targetDir = SlidePlayer.ProjectVectorOnPlane(rotationNormal, targetDir);
            Quaternion tr             = Quaternion.LookRotation(targetDir, rotationNormal);
            Quaternion targetRotation = Quaternion.Slerp(states.mTransform.rotation, tr, states.delta * states.movementVariables.moveAmount * speed);

            //Rotate 180 ?
            var testAngle     = Vector3.Angle(targetDir3, states.mTransform.forward);
            var testAngleSide = Vector3.Angle(targetDir2, states.mTransform.right);

            // Rotate 180 - disabled to test rotation

            // COME BACK - Disabled ground 180s to see how it feels without them

            /*if (states.ground180Enabled)
             * {
             *  if (testAngle > 160 && testAngle < 200)
             *  {
             *      states.testINT = 0;
             *
             *      //Debug.Log("test angle - " + testAngle);
             *      //Debug.Log("test angle side - " + testAngleSide);
             *
             *      // If the player should be rotating to the left
             *      //if (testAngleSide > 90)
             *      //{
             *      //    //states.anim.SetBool(states.hashes.mirror180, true);
             *      //    states.anim.CrossFade(states.hashes.squ_ground_180_mirror, 0.01f);
             *      //}
             *      //else
             *      //{
             *      states.middlePivot = states.mTransform.position + states.mTransform.forward;
             *      states.anim.CrossFade(states.hashes.squ_ground_180, 0.01f);
             *      //}
             *
             *      states.anim.SetBool(states.hashes.waitForAnimation, true);
             *      states.rigid.velocity = Vector3.zero;
             *
             *      //states.storedTargetDir = targetDir;
             *      states.storedTargetDir = targetDir3;
             *  }
             * }*/

            //float direction = 0;
            //float speedOut = 0;
            //StickToWorldSpace(states.transform, Camera.main.transform, states, ref direction, ref speedOut);
            //Debug.Log("Ground Rotation target DIR: " + targetDir);
            //targetRotation = Quaternion.AngleAxis(direction, states.transform.up);
            //states.mTransform.forward = targetRotation * states.transform.forward;
            states.mTransform.rotation = targetRotation;
        }