diff --git a/FallUnity/Assets/Player/PlayerController.cs b/FallUnity/Assets/Player/PlayerController.cs index 94f8801..d3ca2ab 100755 --- a/FallUnity/Assets/Player/PlayerController.cs +++ b/FallUnity/Assets/Player/PlayerController.cs @@ -9,6 +9,14 @@ public float Speed = 5; public float Gravity = 7; + public enum State + { + Walking, + Raking + } + + private State state = State.Walking; + private CharacterController charC; private AnimationHandler anim; // Use this for initialization @@ -25,6 +33,13 @@ public float RunFrameSpeedBoost = 1.4f; private float runCycle = 0.0f; + + public float PushRadius = 0.6f; + public float PushForce = 300.0f; + public float PushPower = 2.0f; + + private float rakeTime = 0.0f; + public float TimeToPushRake = 0.3f; // Update is called once per frame void Update () { @@ -33,7 +48,7 @@ Vector3 dir = new Vector3(); if (input != null) { - if (charC.isGrounded) + if (charC.isGrounded && state == State.Walking) { dir.x = input.Axis(InputSource.InputAxis.MoveX); dir.z = input.Axis(InputSource.InputAxis.MoveY); @@ -93,22 +108,52 @@ Vector3 moved = transform.position - pos; if (moved.magnitude > 0.7f * Time.deltaTime) { - float radius = 0.6f; int layer = LayerMask.GetMask("leaf"); - foreach (Collider c in Physics.OverlapSphere(transform.position, radius, layer)) + foreach (Collider c in Physics.OverlapSphere(transform.position, PushRadius, layer)) { LeafPhysics leaf = c.GetComponentInParent(); if (leaf != null) { Vector3 toLeaf = leaf.transform.position - transform.position; float dist = toLeaf.magnitude; - float power = Mathf.Pow(1.0f - dist / radius, 2.0f) * Time.deltaTime * 300; + float power = Mathf.Pow(1.0f - dist / PushRadius, PushPower) * Time.deltaTime * PushForce; //toLeaf.Normalize(); toLeaf.y += UnityEngine.Random.Range(0.4f, 1.0f); leaf.Body.AddForce(toLeaf * (9.0f + UnityEngine.Random.Range(0, 9.0f)) * power); } } } + + if (state == State.Walking) + { + Vector2 rake = new Vector2(input.Axis(InputSource.InputAxis.RakeX), input.Axis(InputSource.InputAxis.RakeY)); + if (rake.magnitude < 0.2f) + { + rakeTime = 0; + } + else + { + rakeTime += Time.deltaTime; + } + + if (rake.magnitude > 0.7f && rakeTime < TimeToPushRake) + { + state = State.Raking; + + float angle = Mathf.Atan2(rake.y, rake.x); + + if (angle < 0) angle += Mathf.PI * 2; + + AnimationHandler.Direction rakeDir = AnimationHandler.Direction.UpRight; + + if (angle < Mathf.PI / 2.0f) rakeDir = AnimationHandler.Direction.UpRight; + if (angle < Mathf.PI && angle >= Mathf.PI / 2.0f) rakeDir = AnimationHandler.Direction.UpLeft; + if (angle < Mathf.PI * 3.0f / 2.0f && angle >= Mathf.PI) rakeDir = AnimationHandler.Direction.DownLeft; + if (angle >= Mathf.PI * 3.0f / 2.0f) rakeDir = AnimationHandler.Direction.DownRight; + + anim.SetState("Rake", rakeDir, 0); + } + } } private InputSource input = null;