diff --git a/Build/fall_Data/Managed/Assembly-CSharp.dll b/Build/fall_Data/Managed/Assembly-CSharp.dll index 473b708..7e14020 100644 --- a/Build/fall_Data/Managed/Assembly-CSharp.dll +++ b/Build/fall_Data/Managed/Assembly-CSharp.dll Binary files differ diff --git a/Build/fall_Data/Managed/Assembly-CSharp.dll b/Build/fall_Data/Managed/Assembly-CSharp.dll index 473b708..7e14020 100644 --- a/Build/fall_Data/Managed/Assembly-CSharp.dll +++ b/Build/fall_Data/Managed/Assembly-CSharp.dll Binary files differ diff --git a/Build/fall_Data/globalgamemanagers b/Build/fall_Data/globalgamemanagers index 4e34461..e79341a 100644 --- a/Build/fall_Data/globalgamemanagers +++ b/Build/fall_Data/globalgamemanagers Binary files differ diff --git a/Build/fall_Data/Managed/Assembly-CSharp.dll b/Build/fall_Data/Managed/Assembly-CSharp.dll index 473b708..7e14020 100644 --- a/Build/fall_Data/Managed/Assembly-CSharp.dll +++ b/Build/fall_Data/Managed/Assembly-CSharp.dll Binary files differ diff --git a/Build/fall_Data/globalgamemanagers b/Build/fall_Data/globalgamemanagers index 4e34461..e79341a 100644 --- a/Build/fall_Data/globalgamemanagers +++ b/Build/fall_Data/globalgamemanagers Binary files differ diff --git a/Build/fall_Data/globalgamemanagers.assets b/Build/fall_Data/globalgamemanagers.assets index f90a19e..8cb05c1 100644 --- a/Build/fall_Data/globalgamemanagers.assets +++ b/Build/fall_Data/globalgamemanagers.assets Binary files differ diff --git a/Build/fall_Data/Managed/Assembly-CSharp.dll b/Build/fall_Data/Managed/Assembly-CSharp.dll index 473b708..7e14020 100644 --- a/Build/fall_Data/Managed/Assembly-CSharp.dll +++ b/Build/fall_Data/Managed/Assembly-CSharp.dll Binary files differ diff --git a/Build/fall_Data/globalgamemanagers b/Build/fall_Data/globalgamemanagers index 4e34461..e79341a 100644 --- a/Build/fall_Data/globalgamemanagers +++ b/Build/fall_Data/globalgamemanagers Binary files differ diff --git a/Build/fall_Data/globalgamemanagers.assets b/Build/fall_Data/globalgamemanagers.assets index f90a19e..8cb05c1 100644 --- a/Build/fall_Data/globalgamemanagers.assets +++ b/Build/fall_Data/globalgamemanagers.assets Binary files differ diff --git a/Build/fall_Data/level0 b/Build/fall_Data/level0 index f49aed1..4a45106 100644 --- a/Build/fall_Data/level0 +++ b/Build/fall_Data/level0 Binary files differ diff --git a/Build/fall_Data/Managed/Assembly-CSharp.dll b/Build/fall_Data/Managed/Assembly-CSharp.dll index 473b708..7e14020 100644 --- a/Build/fall_Data/Managed/Assembly-CSharp.dll +++ b/Build/fall_Data/Managed/Assembly-CSharp.dll Binary files differ diff --git a/Build/fall_Data/globalgamemanagers b/Build/fall_Data/globalgamemanagers index 4e34461..e79341a 100644 --- a/Build/fall_Data/globalgamemanagers +++ b/Build/fall_Data/globalgamemanagers Binary files differ diff --git a/Build/fall_Data/globalgamemanagers.assets b/Build/fall_Data/globalgamemanagers.assets index f90a19e..8cb05c1 100644 --- a/Build/fall_Data/globalgamemanagers.assets +++ b/Build/fall_Data/globalgamemanagers.assets Binary files differ diff --git a/Build/fall_Data/level0 b/Build/fall_Data/level0 index f49aed1..4a45106 100644 --- a/Build/fall_Data/level0 +++ b/Build/fall_Data/level0 Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets b/Build/fall_Data/sharedassets0.assets index da4c84e..3e933fc 100644 --- a/Build/fall_Data/sharedassets0.assets +++ b/Build/fall_Data/sharedassets0.assets Binary files differ diff --git a/Build/fall_Data/Managed/Assembly-CSharp.dll b/Build/fall_Data/Managed/Assembly-CSharp.dll index 473b708..7e14020 100644 --- a/Build/fall_Data/Managed/Assembly-CSharp.dll +++ b/Build/fall_Data/Managed/Assembly-CSharp.dll Binary files differ diff --git a/Build/fall_Data/globalgamemanagers b/Build/fall_Data/globalgamemanagers index 4e34461..e79341a 100644 --- a/Build/fall_Data/globalgamemanagers +++ b/Build/fall_Data/globalgamemanagers Binary files differ diff --git a/Build/fall_Data/globalgamemanagers.assets b/Build/fall_Data/globalgamemanagers.assets index f90a19e..8cb05c1 100644 --- a/Build/fall_Data/globalgamemanagers.assets +++ b/Build/fall_Data/globalgamemanagers.assets Binary files differ diff --git a/Build/fall_Data/level0 b/Build/fall_Data/level0 index f49aed1..4a45106 100644 --- a/Build/fall_Data/level0 +++ b/Build/fall_Data/level0 Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets b/Build/fall_Data/sharedassets0.assets index da4c84e..3e933fc 100644 --- a/Build/fall_Data/sharedassets0.assets +++ b/Build/fall_Data/sharedassets0.assets Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets.resS b/Build/fall_Data/sharedassets0.assets.resS index 811ed41..091e899 100644 --- a/Build/fall_Data/sharedassets0.assets.resS +++ b/Build/fall_Data/sharedassets0.assets.resS Binary files differ diff --git a/Build/fall_Data/Managed/Assembly-CSharp.dll b/Build/fall_Data/Managed/Assembly-CSharp.dll index 473b708..7e14020 100644 --- a/Build/fall_Data/Managed/Assembly-CSharp.dll +++ b/Build/fall_Data/Managed/Assembly-CSharp.dll Binary files differ diff --git a/Build/fall_Data/globalgamemanagers b/Build/fall_Data/globalgamemanagers index 4e34461..e79341a 100644 --- a/Build/fall_Data/globalgamemanagers +++ b/Build/fall_Data/globalgamemanagers Binary files differ diff --git a/Build/fall_Data/globalgamemanagers.assets b/Build/fall_Data/globalgamemanagers.assets index f90a19e..8cb05c1 100644 --- a/Build/fall_Data/globalgamemanagers.assets +++ b/Build/fall_Data/globalgamemanagers.assets Binary files differ diff --git a/Build/fall_Data/level0 b/Build/fall_Data/level0 index f49aed1..4a45106 100644 --- a/Build/fall_Data/level0 +++ b/Build/fall_Data/level0 Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets b/Build/fall_Data/sharedassets0.assets index da4c84e..3e933fc 100644 --- a/Build/fall_Data/sharedassets0.assets +++ b/Build/fall_Data/sharedassets0.assets Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets.resS b/Build/fall_Data/sharedassets0.assets.resS index 811ed41..091e899 100644 --- a/Build/fall_Data/sharedassets0.assets.resS +++ b/Build/fall_Data/sharedassets0.assets.resS Binary files differ diff --git a/FallUnity/Assets/Game/LeafSpawner.cs b/FallUnity/Assets/Game/LeafSpawner.cs index dd7cba9..beeff78 100644 --- a/FallUnity/Assets/Game/LeafSpawner.cs +++ b/FallUnity/Assets/Game/LeafSpawner.cs @@ -22,11 +22,13 @@ time += Time.deltaTime; while (time > interval) { + time -= interval; if (leafHandler != null && leafHandler.NumLeaves < leafHandler.MaxLeaves) - { - time -= interval; - Vector2 offset = Random.insideUnitCircle; - Vector3 point = transform.position + new Vector3(offset.x * Radius, 0, offset.y * Radius); + { + float angle = UnityEngine.Random.Range(0, Mathf.PI * 2); + float r = UnityEngine.Random.Range(0, Radius); + + Vector3 point = transform.position + new Vector3(Mathf.Sin(angle) * r, 0, Mathf.Cos(angle) * r); LeafPhysics leaf = GameObject.Instantiate(Leafs[Random.Range(0, Leafs.Length)]); leaves.Add(leaf); leaf.transform.position = point; diff --git a/Build/fall_Data/Managed/Assembly-CSharp.dll b/Build/fall_Data/Managed/Assembly-CSharp.dll index 473b708..7e14020 100644 --- a/Build/fall_Data/Managed/Assembly-CSharp.dll +++ b/Build/fall_Data/Managed/Assembly-CSharp.dll Binary files differ diff --git a/Build/fall_Data/globalgamemanagers b/Build/fall_Data/globalgamemanagers index 4e34461..e79341a 100644 --- a/Build/fall_Data/globalgamemanagers +++ b/Build/fall_Data/globalgamemanagers Binary files differ diff --git a/Build/fall_Data/globalgamemanagers.assets b/Build/fall_Data/globalgamemanagers.assets index f90a19e..8cb05c1 100644 --- a/Build/fall_Data/globalgamemanagers.assets +++ b/Build/fall_Data/globalgamemanagers.assets Binary files differ diff --git a/Build/fall_Data/level0 b/Build/fall_Data/level0 index f49aed1..4a45106 100644 --- a/Build/fall_Data/level0 +++ b/Build/fall_Data/level0 Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets b/Build/fall_Data/sharedassets0.assets index da4c84e..3e933fc 100644 --- a/Build/fall_Data/sharedassets0.assets +++ b/Build/fall_Data/sharedassets0.assets Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets.resS b/Build/fall_Data/sharedassets0.assets.resS index 811ed41..091e899 100644 --- a/Build/fall_Data/sharedassets0.assets.resS +++ b/Build/fall_Data/sharedassets0.assets.resS Binary files differ diff --git a/FallUnity/Assets/Game/LeafSpawner.cs b/FallUnity/Assets/Game/LeafSpawner.cs index dd7cba9..beeff78 100644 --- a/FallUnity/Assets/Game/LeafSpawner.cs +++ b/FallUnity/Assets/Game/LeafSpawner.cs @@ -22,11 +22,13 @@ time += Time.deltaTime; while (time > interval) { + time -= interval; if (leafHandler != null && leafHandler.NumLeaves < leafHandler.MaxLeaves) - { - time -= interval; - Vector2 offset = Random.insideUnitCircle; - Vector3 point = transform.position + new Vector3(offset.x * Radius, 0, offset.y * Radius); + { + float angle = UnityEngine.Random.Range(0, Mathf.PI * 2); + float r = UnityEngine.Random.Range(0, Radius); + + Vector3 point = transform.position + new Vector3(Mathf.Sin(angle) * r, 0, Mathf.Cos(angle) * r); LeafPhysics leaf = GameObject.Instantiate(Leafs[Random.Range(0, Leafs.Length)]); leaves.Add(leaf); leaf.transform.position = point; diff --git a/FallUnity/Assets/Leaves/LeafHandler.cs b/FallUnity/Assets/Leaves/LeafHandler.cs index f931ce3..8ba3c89 100644 --- a/FallUnity/Assets/Leaves/LeafHandler.cs +++ b/FallUnity/Assets/Leaves/LeafHandler.cs @@ -1,28 +1,183 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class LeafHandler : MonoBehaviour { - private int numLeaves = 0; - public int NumLeaves { get { return numLeaves; } } - public int MaxLeaves = 700; - - public void AddLeaf() +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class LeafHandler : MonoBehaviour { + public int NumLeaves = 0; + public int MaxLeaves = 700; + + private HashSet leafs = new HashSet(); + + public void AddLeaf(LeafPhysics l) { - numLeaves++; - } - - public void RemoveLeaf() - { - numLeaves--; + leafs.Add(l); + NumLeaves = leafs.Count; } + + public void RemoveLeaf(LeafPhysics l) + { + leafs.Remove(l); + NumLeaves = leafs.Count; + } + + private SimpleTimer timer; + private SimpleTween tween; // Use this for initialization - void Start () { - - } - - // Update is called once per frame - void Update () { - - } -} + void Start () { + timer = new SimpleTimer(); + tween = new SimpleTween(); + //WaitForNextEvent(); + PickNextEvent(); + } + + private void WaitForNextEvent() + { + timer.Start(UnityEngine.Random.Range(7.0f, 20.0f), PickNextEvent); + } + + private Vector3 windForce = new Vector3(); + private Vector2 whirlwindCenter = new Vector3(); + private float whirlwindRadius = 0; + private float whirlwindForce = 0; + private float whirlwindForceUp = 0; + + private void PickNextEvent() + { + int eventType = UnityEngine.Random.Range(0, 2); + switch (eventType) + { + case 0: + { + // wind + float windAngle = UnityEngine.Random.Range(0, Mathf.PI * 2); + Vector3 windVector = new Vector3(Mathf.Sin(windAngle), 0, Mathf.Cos(windAngle)); + windVector.y = UnityEngine.Random.Range(0.8f, 1.2f); + float windStrength = UnityEngine.Random.Range(0.8f, 1.3f); + float fadeTime = UnityEngine.Random.Range(1.0f, 3.0f); + float windTime = UnityEngine.Random.Range(3.0f, 5.0f); + + Debug.LogError("WIND: V:" + windVector + " S:" + windStrength + " F:" + fadeTime + " T:" + windTime); + + tween.Init(v => + { + windForce = windVector * windStrength * v; + }, SimpleTween.EaseLinear, 0, 1, fadeTime); + tween.OnFinish = () => + { + tween.Init(v => + { + //windForce = windVector * windStrength * (Mathf.Sin(v * 25) + 1) * 0.2f; + }, SimpleTween.EaseLinear, 0, windTime, windTime); + tween.OnFinish = () => + { + tween.Init(v => + { + windForce = windVector * windStrength * v; + }, SimpleTween.EaseLinear, 1, 0, fadeTime); + tween.OnFinish = () => + { + WaitForNextEvent(); + }; + }; + + }; + break; + } + case 1: + { + // whirlwind + whirlwindCenter = UnityEngine.Random.insideUnitCircle * UnityEngine.Random.Range(0, 6.0f); + whirlwindRadius = UnityEngine.Random.Range(3.0f, 4.0f); + float maxWhirlwindForce = UnityEngine.Random.Range(1.0f, 1.6f); + float maxWhirlwindForceUp = UnityEngine.Random.Range(0.3f, 0.8f); + + float fadeTime = UnityEngine.Random.Range(2.0f, 4.0f); + float windTime = UnityEngine.Random.Range(6.0f, 8.0f); + + Debug.LogError("WHIRLWIND: C:" + whirlwindCenter + " R:" + whirlwindRadius + " F:" + maxWhirlwindForce + " U:" + maxWhirlwindForceUp + " F:" + fadeTime + " T:" + windTime); + + tween.Init(v => + { + whirlwindForce = maxWhirlwindForce * v; + whirlwindForceUp = maxWhirlwindForceUp * v; + }, SimpleTween.EaseLinear, 0, 1, fadeTime); + tween.OnFinish = () => + { + tween.Init(v => + { + //windForce = windVector * windStrength * (Mathf.Sin(v * 25) + 1) * 0.2f; + }, SimpleTween.EaseLinear, 0, windTime, windTime); + tween.OnFinish = () => + { + tween.Init(v => + { + whirlwindForce = maxWhirlwindForce * v; + whirlwindForceUp = maxWhirlwindForceUp * v; + }, SimpleTween.EaseLinear, 1, 0, fadeTime); + tween.OnFinish = () => + { + WaitForNextEvent(); + }; + }; + + }; + + break; + } + } + } + + // Update is called once per frame + void Update () { + bool hasWind = windForce.sqrMagnitude > 0.00001f; + bool hasWhirlwind = whirlwindForce > 0; + Vector2 windDir = new Vector2(windForce.x, windForce.y); + windDir.Normalize(); + + float distAway = 9.0f; + + + foreach (LeafPhysics leaf in leafs) + { + if (hasWind && (UnityEngine.Random.Range(0, 1f) < 0.25f || !leaf.Resting)) + { + float amount = Vector2.Dot(new Vector2(leaf.Body.velocity.x, leaf.Body.velocity.z), windDir); + amount = Math.Max(0, Math.Min(1, 8 - amount)); + leaf.Body.AddForce(new Vector3(windForce.x * UnityEngine.Random.Range(0.75f, 1.0f), + windForce.y * UnityEngine.Random.Range(0.9f, 1.0f), + windForce.z * UnityEngine.Random.Range(0.75f, 1.0f)) * Time.deltaTime * 60 * (leaf.Resting ? 3.0f : 0.4f)); + } + Vector2 d = new Vector2(leaf.transform.position.x, leaf.transform.position.z); + + if (hasWhirlwind && (UnityEngine.Random.Range(0, 1f) < 0.15f || !leaf.Resting)) + { + Vector2 offset = new Vector2(leaf.transform.position.x, leaf.transform.position.z) - whirlwindCenter; + Vector2 offsetN = offset.normalized; + float distFrom = offset.magnitude; + + if (distFrom < whirlwindRadius) + { + + Vector2 tangent = new Vector2(-offsetN.y, offsetN.x); + Vector2 force = tangent * (whirlwindRadius - distFrom) * whirlwindForce + offset * -0.9f; + + Vector3 force3D = new Vector3(force.x, whirlwindForceUp * (whirlwindRadius - distFrom + 2), force.y); + + leaf.Body.AddForce(new Vector3(force3D.x * UnityEngine.Random.Range(0.75f, 1.0f), + force3D.y * UnityEngine.Random.Range(0.9f, 1.0f), + force3D.z * UnityEngine.Random.Range(0.75f, 1.0f)) * Time.deltaTime * 60 * (leaf.Resting ? 3.0f : 0.4f)); + + } + + + } + + if (d.magnitude > distAway && !leaf.Resting) + { + //leaf.Body.apply + } + } + + } +} diff --git a/Build/fall_Data/Managed/Assembly-CSharp.dll b/Build/fall_Data/Managed/Assembly-CSharp.dll index 473b708..7e14020 100644 --- a/Build/fall_Data/Managed/Assembly-CSharp.dll +++ b/Build/fall_Data/Managed/Assembly-CSharp.dll Binary files differ diff --git a/Build/fall_Data/globalgamemanagers b/Build/fall_Data/globalgamemanagers index 4e34461..e79341a 100644 --- a/Build/fall_Data/globalgamemanagers +++ b/Build/fall_Data/globalgamemanagers Binary files differ diff --git a/Build/fall_Data/globalgamemanagers.assets b/Build/fall_Data/globalgamemanagers.assets index f90a19e..8cb05c1 100644 --- a/Build/fall_Data/globalgamemanagers.assets +++ b/Build/fall_Data/globalgamemanagers.assets Binary files differ diff --git a/Build/fall_Data/level0 b/Build/fall_Data/level0 index f49aed1..4a45106 100644 --- a/Build/fall_Data/level0 +++ b/Build/fall_Data/level0 Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets b/Build/fall_Data/sharedassets0.assets index da4c84e..3e933fc 100644 --- a/Build/fall_Data/sharedassets0.assets +++ b/Build/fall_Data/sharedassets0.assets Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets.resS b/Build/fall_Data/sharedassets0.assets.resS index 811ed41..091e899 100644 --- a/Build/fall_Data/sharedassets0.assets.resS +++ b/Build/fall_Data/sharedassets0.assets.resS Binary files differ diff --git a/FallUnity/Assets/Game/LeafSpawner.cs b/FallUnity/Assets/Game/LeafSpawner.cs index dd7cba9..beeff78 100644 --- a/FallUnity/Assets/Game/LeafSpawner.cs +++ b/FallUnity/Assets/Game/LeafSpawner.cs @@ -22,11 +22,13 @@ time += Time.deltaTime; while (time > interval) { + time -= interval; if (leafHandler != null && leafHandler.NumLeaves < leafHandler.MaxLeaves) - { - time -= interval; - Vector2 offset = Random.insideUnitCircle; - Vector3 point = transform.position + new Vector3(offset.x * Radius, 0, offset.y * Radius); + { + float angle = UnityEngine.Random.Range(0, Mathf.PI * 2); + float r = UnityEngine.Random.Range(0, Radius); + + Vector3 point = transform.position + new Vector3(Mathf.Sin(angle) * r, 0, Mathf.Cos(angle) * r); LeafPhysics leaf = GameObject.Instantiate(Leafs[Random.Range(0, Leafs.Length)]); leaves.Add(leaf); leaf.transform.position = point; diff --git a/FallUnity/Assets/Leaves/LeafHandler.cs b/FallUnity/Assets/Leaves/LeafHandler.cs index f931ce3..8ba3c89 100644 --- a/FallUnity/Assets/Leaves/LeafHandler.cs +++ b/FallUnity/Assets/Leaves/LeafHandler.cs @@ -1,28 +1,183 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class LeafHandler : MonoBehaviour { - private int numLeaves = 0; - public int NumLeaves { get { return numLeaves; } } - public int MaxLeaves = 700; - - public void AddLeaf() +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class LeafHandler : MonoBehaviour { + public int NumLeaves = 0; + public int MaxLeaves = 700; + + private HashSet leafs = new HashSet(); + + public void AddLeaf(LeafPhysics l) { - numLeaves++; - } - - public void RemoveLeaf() - { - numLeaves--; + leafs.Add(l); + NumLeaves = leafs.Count; } + + public void RemoveLeaf(LeafPhysics l) + { + leafs.Remove(l); + NumLeaves = leafs.Count; + } + + private SimpleTimer timer; + private SimpleTween tween; // Use this for initialization - void Start () { - - } - - // Update is called once per frame - void Update () { - - } -} + void Start () { + timer = new SimpleTimer(); + tween = new SimpleTween(); + //WaitForNextEvent(); + PickNextEvent(); + } + + private void WaitForNextEvent() + { + timer.Start(UnityEngine.Random.Range(7.0f, 20.0f), PickNextEvent); + } + + private Vector3 windForce = new Vector3(); + private Vector2 whirlwindCenter = new Vector3(); + private float whirlwindRadius = 0; + private float whirlwindForce = 0; + private float whirlwindForceUp = 0; + + private void PickNextEvent() + { + int eventType = UnityEngine.Random.Range(0, 2); + switch (eventType) + { + case 0: + { + // wind + float windAngle = UnityEngine.Random.Range(0, Mathf.PI * 2); + Vector3 windVector = new Vector3(Mathf.Sin(windAngle), 0, Mathf.Cos(windAngle)); + windVector.y = UnityEngine.Random.Range(0.8f, 1.2f); + float windStrength = UnityEngine.Random.Range(0.8f, 1.3f); + float fadeTime = UnityEngine.Random.Range(1.0f, 3.0f); + float windTime = UnityEngine.Random.Range(3.0f, 5.0f); + + Debug.LogError("WIND: V:" + windVector + " S:" + windStrength + " F:" + fadeTime + " T:" + windTime); + + tween.Init(v => + { + windForce = windVector * windStrength * v; + }, SimpleTween.EaseLinear, 0, 1, fadeTime); + tween.OnFinish = () => + { + tween.Init(v => + { + //windForce = windVector * windStrength * (Mathf.Sin(v * 25) + 1) * 0.2f; + }, SimpleTween.EaseLinear, 0, windTime, windTime); + tween.OnFinish = () => + { + tween.Init(v => + { + windForce = windVector * windStrength * v; + }, SimpleTween.EaseLinear, 1, 0, fadeTime); + tween.OnFinish = () => + { + WaitForNextEvent(); + }; + }; + + }; + break; + } + case 1: + { + // whirlwind + whirlwindCenter = UnityEngine.Random.insideUnitCircle * UnityEngine.Random.Range(0, 6.0f); + whirlwindRadius = UnityEngine.Random.Range(3.0f, 4.0f); + float maxWhirlwindForce = UnityEngine.Random.Range(1.0f, 1.6f); + float maxWhirlwindForceUp = UnityEngine.Random.Range(0.3f, 0.8f); + + float fadeTime = UnityEngine.Random.Range(2.0f, 4.0f); + float windTime = UnityEngine.Random.Range(6.0f, 8.0f); + + Debug.LogError("WHIRLWIND: C:" + whirlwindCenter + " R:" + whirlwindRadius + " F:" + maxWhirlwindForce + " U:" + maxWhirlwindForceUp + " F:" + fadeTime + " T:" + windTime); + + tween.Init(v => + { + whirlwindForce = maxWhirlwindForce * v; + whirlwindForceUp = maxWhirlwindForceUp * v; + }, SimpleTween.EaseLinear, 0, 1, fadeTime); + tween.OnFinish = () => + { + tween.Init(v => + { + //windForce = windVector * windStrength * (Mathf.Sin(v * 25) + 1) * 0.2f; + }, SimpleTween.EaseLinear, 0, windTime, windTime); + tween.OnFinish = () => + { + tween.Init(v => + { + whirlwindForce = maxWhirlwindForce * v; + whirlwindForceUp = maxWhirlwindForceUp * v; + }, SimpleTween.EaseLinear, 1, 0, fadeTime); + tween.OnFinish = () => + { + WaitForNextEvent(); + }; + }; + + }; + + break; + } + } + } + + // Update is called once per frame + void Update () { + bool hasWind = windForce.sqrMagnitude > 0.00001f; + bool hasWhirlwind = whirlwindForce > 0; + Vector2 windDir = new Vector2(windForce.x, windForce.y); + windDir.Normalize(); + + float distAway = 9.0f; + + + foreach (LeafPhysics leaf in leafs) + { + if (hasWind && (UnityEngine.Random.Range(0, 1f) < 0.25f || !leaf.Resting)) + { + float amount = Vector2.Dot(new Vector2(leaf.Body.velocity.x, leaf.Body.velocity.z), windDir); + amount = Math.Max(0, Math.Min(1, 8 - amount)); + leaf.Body.AddForce(new Vector3(windForce.x * UnityEngine.Random.Range(0.75f, 1.0f), + windForce.y * UnityEngine.Random.Range(0.9f, 1.0f), + windForce.z * UnityEngine.Random.Range(0.75f, 1.0f)) * Time.deltaTime * 60 * (leaf.Resting ? 3.0f : 0.4f)); + } + Vector2 d = new Vector2(leaf.transform.position.x, leaf.transform.position.z); + + if (hasWhirlwind && (UnityEngine.Random.Range(0, 1f) < 0.15f || !leaf.Resting)) + { + Vector2 offset = new Vector2(leaf.transform.position.x, leaf.transform.position.z) - whirlwindCenter; + Vector2 offsetN = offset.normalized; + float distFrom = offset.magnitude; + + if (distFrom < whirlwindRadius) + { + + Vector2 tangent = new Vector2(-offsetN.y, offsetN.x); + Vector2 force = tangent * (whirlwindRadius - distFrom) * whirlwindForce + offset * -0.9f; + + Vector3 force3D = new Vector3(force.x, whirlwindForceUp * (whirlwindRadius - distFrom + 2), force.y); + + leaf.Body.AddForce(new Vector3(force3D.x * UnityEngine.Random.Range(0.75f, 1.0f), + force3D.y * UnityEngine.Random.Range(0.9f, 1.0f), + force3D.z * UnityEngine.Random.Range(0.75f, 1.0f)) * Time.deltaTime * 60 * (leaf.Resting ? 3.0f : 0.4f)); + + } + + + } + + if (d.magnitude > distAway && !leaf.Resting) + { + //leaf.Body.apply + } + } + + } +} diff --git a/FallUnity/Assets/Leaves/LeafPhysics.cs b/FallUnity/Assets/Leaves/LeafPhysics.cs index 3355523..d59bfba 100755 --- a/FallUnity/Assets/Leaves/LeafPhysics.cs +++ b/FallUnity/Assets/Leaves/LeafPhysics.cs @@ -9,6 +9,10 @@ public Rigidbody Body { get { return body; } } private LeafHandler leafHandler; + + private List mats = new List(); + public IEnumerable Mats { get { return mats; } } + // Use this for initialization void Start () { body = GetComponentInChildren(); @@ -23,18 +27,32 @@ leafHandler = GameObject.FindObjectOfType(); if (leafHandler != null) { - leafHandler.AddLeaf(); + leafHandler.AddLeaf(this); } - deadLifeSpan = UnityEngine.Random.Range(20, 40); + deadLifeSpan = UnityEngine.Random.Range(20, 40.0f); deadLife = deadLifeSpan; + + foreach (MeshRenderer mr in GetComponentsInChildren()) + { + mats.Add(mr.material); + } + + Color c = Color.white; + c.r = UnityEngine.Random.Range(0.6f, 1.0f); + c.g = UnityEngine.Random.Range(0.6f, 1.0f); + c.b = UnityEngine.Random.Range(0.6f, 1.0f); + foreach (Material m in mats) + { + m.color = c; + } } void OnDestroy() { if (leafHandler != null) { - leafHandler.RemoveLeaf(); + leafHandler.RemoveLeaf(this); } } @@ -109,6 +127,17 @@ private bool isFading = false; + public bool Resting = false; + private void FixedUpdate() + { + Resting = false; + } + + private void OnCollisionStay(Collision collision) + { + Resting = collision.contacts.Length > 0 && Mathf.Abs(collision.contacts[0].normal.y) > 0.7f; + } + // Update is called once per frame void Update () { if (!body.isKinematic && body.velocity.sqrMagnitude > 0.01f) @@ -145,16 +174,11 @@ } else { - deadLife -= Time.deltaTime; + deadLife -= Time.deltaTime * (leafHandler.NumLeaves >= leafHandler.MaxLeaves ? 3 : 1); if (deadLife <= 0 && !isFading) { isFading = true; SimpleTween tweenOut = new SimpleTween(); - HashSet mats = new HashSet(); - foreach (MeshRenderer mr in GetComponentsInChildren()) - { - mats.Add(mr.material); - } tweenOut.Init(v => { foreach (Material m in mats) diff --git a/Build/fall_Data/Managed/Assembly-CSharp.dll b/Build/fall_Data/Managed/Assembly-CSharp.dll index 473b708..7e14020 100644 --- a/Build/fall_Data/Managed/Assembly-CSharp.dll +++ b/Build/fall_Data/Managed/Assembly-CSharp.dll Binary files differ diff --git a/Build/fall_Data/globalgamemanagers b/Build/fall_Data/globalgamemanagers index 4e34461..e79341a 100644 --- a/Build/fall_Data/globalgamemanagers +++ b/Build/fall_Data/globalgamemanagers Binary files differ diff --git a/Build/fall_Data/globalgamemanagers.assets b/Build/fall_Data/globalgamemanagers.assets index f90a19e..8cb05c1 100644 --- a/Build/fall_Data/globalgamemanagers.assets +++ b/Build/fall_Data/globalgamemanagers.assets Binary files differ diff --git a/Build/fall_Data/level0 b/Build/fall_Data/level0 index f49aed1..4a45106 100644 --- a/Build/fall_Data/level0 +++ b/Build/fall_Data/level0 Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets b/Build/fall_Data/sharedassets0.assets index da4c84e..3e933fc 100644 --- a/Build/fall_Data/sharedassets0.assets +++ b/Build/fall_Data/sharedassets0.assets Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets.resS b/Build/fall_Data/sharedassets0.assets.resS index 811ed41..091e899 100644 --- a/Build/fall_Data/sharedassets0.assets.resS +++ b/Build/fall_Data/sharedassets0.assets.resS Binary files differ diff --git a/FallUnity/Assets/Game/LeafSpawner.cs b/FallUnity/Assets/Game/LeafSpawner.cs index dd7cba9..beeff78 100644 --- a/FallUnity/Assets/Game/LeafSpawner.cs +++ b/FallUnity/Assets/Game/LeafSpawner.cs @@ -22,11 +22,13 @@ time += Time.deltaTime; while (time > interval) { + time -= interval; if (leafHandler != null && leafHandler.NumLeaves < leafHandler.MaxLeaves) - { - time -= interval; - Vector2 offset = Random.insideUnitCircle; - Vector3 point = transform.position + new Vector3(offset.x * Radius, 0, offset.y * Radius); + { + float angle = UnityEngine.Random.Range(0, Mathf.PI * 2); + float r = UnityEngine.Random.Range(0, Radius); + + Vector3 point = transform.position + new Vector3(Mathf.Sin(angle) * r, 0, Mathf.Cos(angle) * r); LeafPhysics leaf = GameObject.Instantiate(Leafs[Random.Range(0, Leafs.Length)]); leaves.Add(leaf); leaf.transform.position = point; diff --git a/FallUnity/Assets/Leaves/LeafHandler.cs b/FallUnity/Assets/Leaves/LeafHandler.cs index f931ce3..8ba3c89 100644 --- a/FallUnity/Assets/Leaves/LeafHandler.cs +++ b/FallUnity/Assets/Leaves/LeafHandler.cs @@ -1,28 +1,183 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class LeafHandler : MonoBehaviour { - private int numLeaves = 0; - public int NumLeaves { get { return numLeaves; } } - public int MaxLeaves = 700; - - public void AddLeaf() +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class LeafHandler : MonoBehaviour { + public int NumLeaves = 0; + public int MaxLeaves = 700; + + private HashSet leafs = new HashSet(); + + public void AddLeaf(LeafPhysics l) { - numLeaves++; - } - - public void RemoveLeaf() - { - numLeaves--; + leafs.Add(l); + NumLeaves = leafs.Count; } + + public void RemoveLeaf(LeafPhysics l) + { + leafs.Remove(l); + NumLeaves = leafs.Count; + } + + private SimpleTimer timer; + private SimpleTween tween; // Use this for initialization - void Start () { - - } - - // Update is called once per frame - void Update () { - - } -} + void Start () { + timer = new SimpleTimer(); + tween = new SimpleTween(); + //WaitForNextEvent(); + PickNextEvent(); + } + + private void WaitForNextEvent() + { + timer.Start(UnityEngine.Random.Range(7.0f, 20.0f), PickNextEvent); + } + + private Vector3 windForce = new Vector3(); + private Vector2 whirlwindCenter = new Vector3(); + private float whirlwindRadius = 0; + private float whirlwindForce = 0; + private float whirlwindForceUp = 0; + + private void PickNextEvent() + { + int eventType = UnityEngine.Random.Range(0, 2); + switch (eventType) + { + case 0: + { + // wind + float windAngle = UnityEngine.Random.Range(0, Mathf.PI * 2); + Vector3 windVector = new Vector3(Mathf.Sin(windAngle), 0, Mathf.Cos(windAngle)); + windVector.y = UnityEngine.Random.Range(0.8f, 1.2f); + float windStrength = UnityEngine.Random.Range(0.8f, 1.3f); + float fadeTime = UnityEngine.Random.Range(1.0f, 3.0f); + float windTime = UnityEngine.Random.Range(3.0f, 5.0f); + + Debug.LogError("WIND: V:" + windVector + " S:" + windStrength + " F:" + fadeTime + " T:" + windTime); + + tween.Init(v => + { + windForce = windVector * windStrength * v; + }, SimpleTween.EaseLinear, 0, 1, fadeTime); + tween.OnFinish = () => + { + tween.Init(v => + { + //windForce = windVector * windStrength * (Mathf.Sin(v * 25) + 1) * 0.2f; + }, SimpleTween.EaseLinear, 0, windTime, windTime); + tween.OnFinish = () => + { + tween.Init(v => + { + windForce = windVector * windStrength * v; + }, SimpleTween.EaseLinear, 1, 0, fadeTime); + tween.OnFinish = () => + { + WaitForNextEvent(); + }; + }; + + }; + break; + } + case 1: + { + // whirlwind + whirlwindCenter = UnityEngine.Random.insideUnitCircle * UnityEngine.Random.Range(0, 6.0f); + whirlwindRadius = UnityEngine.Random.Range(3.0f, 4.0f); + float maxWhirlwindForce = UnityEngine.Random.Range(1.0f, 1.6f); + float maxWhirlwindForceUp = UnityEngine.Random.Range(0.3f, 0.8f); + + float fadeTime = UnityEngine.Random.Range(2.0f, 4.0f); + float windTime = UnityEngine.Random.Range(6.0f, 8.0f); + + Debug.LogError("WHIRLWIND: C:" + whirlwindCenter + " R:" + whirlwindRadius + " F:" + maxWhirlwindForce + " U:" + maxWhirlwindForceUp + " F:" + fadeTime + " T:" + windTime); + + tween.Init(v => + { + whirlwindForce = maxWhirlwindForce * v; + whirlwindForceUp = maxWhirlwindForceUp * v; + }, SimpleTween.EaseLinear, 0, 1, fadeTime); + tween.OnFinish = () => + { + tween.Init(v => + { + //windForce = windVector * windStrength * (Mathf.Sin(v * 25) + 1) * 0.2f; + }, SimpleTween.EaseLinear, 0, windTime, windTime); + tween.OnFinish = () => + { + tween.Init(v => + { + whirlwindForce = maxWhirlwindForce * v; + whirlwindForceUp = maxWhirlwindForceUp * v; + }, SimpleTween.EaseLinear, 1, 0, fadeTime); + tween.OnFinish = () => + { + WaitForNextEvent(); + }; + }; + + }; + + break; + } + } + } + + // Update is called once per frame + void Update () { + bool hasWind = windForce.sqrMagnitude > 0.00001f; + bool hasWhirlwind = whirlwindForce > 0; + Vector2 windDir = new Vector2(windForce.x, windForce.y); + windDir.Normalize(); + + float distAway = 9.0f; + + + foreach (LeafPhysics leaf in leafs) + { + if (hasWind && (UnityEngine.Random.Range(0, 1f) < 0.25f || !leaf.Resting)) + { + float amount = Vector2.Dot(new Vector2(leaf.Body.velocity.x, leaf.Body.velocity.z), windDir); + amount = Math.Max(0, Math.Min(1, 8 - amount)); + leaf.Body.AddForce(new Vector3(windForce.x * UnityEngine.Random.Range(0.75f, 1.0f), + windForce.y * UnityEngine.Random.Range(0.9f, 1.0f), + windForce.z * UnityEngine.Random.Range(0.75f, 1.0f)) * Time.deltaTime * 60 * (leaf.Resting ? 3.0f : 0.4f)); + } + Vector2 d = new Vector2(leaf.transform.position.x, leaf.transform.position.z); + + if (hasWhirlwind && (UnityEngine.Random.Range(0, 1f) < 0.15f || !leaf.Resting)) + { + Vector2 offset = new Vector2(leaf.transform.position.x, leaf.transform.position.z) - whirlwindCenter; + Vector2 offsetN = offset.normalized; + float distFrom = offset.magnitude; + + if (distFrom < whirlwindRadius) + { + + Vector2 tangent = new Vector2(-offsetN.y, offsetN.x); + Vector2 force = tangent * (whirlwindRadius - distFrom) * whirlwindForce + offset * -0.9f; + + Vector3 force3D = new Vector3(force.x, whirlwindForceUp * (whirlwindRadius - distFrom + 2), force.y); + + leaf.Body.AddForce(new Vector3(force3D.x * UnityEngine.Random.Range(0.75f, 1.0f), + force3D.y * UnityEngine.Random.Range(0.9f, 1.0f), + force3D.z * UnityEngine.Random.Range(0.75f, 1.0f)) * Time.deltaTime * 60 * (leaf.Resting ? 3.0f : 0.4f)); + + } + + + } + + if (d.magnitude > distAway && !leaf.Resting) + { + //leaf.Body.apply + } + } + + } +} diff --git a/FallUnity/Assets/Leaves/LeafPhysics.cs b/FallUnity/Assets/Leaves/LeafPhysics.cs index 3355523..d59bfba 100755 --- a/FallUnity/Assets/Leaves/LeafPhysics.cs +++ b/FallUnity/Assets/Leaves/LeafPhysics.cs @@ -9,6 +9,10 @@ public Rigidbody Body { get { return body; } } private LeafHandler leafHandler; + + private List mats = new List(); + public IEnumerable Mats { get { return mats; } } + // Use this for initialization void Start () { body = GetComponentInChildren(); @@ -23,18 +27,32 @@ leafHandler = GameObject.FindObjectOfType(); if (leafHandler != null) { - leafHandler.AddLeaf(); + leafHandler.AddLeaf(this); } - deadLifeSpan = UnityEngine.Random.Range(20, 40); + deadLifeSpan = UnityEngine.Random.Range(20, 40.0f); deadLife = deadLifeSpan; + + foreach (MeshRenderer mr in GetComponentsInChildren()) + { + mats.Add(mr.material); + } + + Color c = Color.white; + c.r = UnityEngine.Random.Range(0.6f, 1.0f); + c.g = UnityEngine.Random.Range(0.6f, 1.0f); + c.b = UnityEngine.Random.Range(0.6f, 1.0f); + foreach (Material m in mats) + { + m.color = c; + } } void OnDestroy() { if (leafHandler != null) { - leafHandler.RemoveLeaf(); + leafHandler.RemoveLeaf(this); } } @@ -109,6 +127,17 @@ private bool isFading = false; + public bool Resting = false; + private void FixedUpdate() + { + Resting = false; + } + + private void OnCollisionStay(Collision collision) + { + Resting = collision.contacts.Length > 0 && Mathf.Abs(collision.contacts[0].normal.y) > 0.7f; + } + // Update is called once per frame void Update () { if (!body.isKinematic && body.velocity.sqrMagnitude > 0.01f) @@ -145,16 +174,11 @@ } else { - deadLife -= Time.deltaTime; + deadLife -= Time.deltaTime * (leafHandler.NumLeaves >= leafHandler.MaxLeaves ? 3 : 1); if (deadLife <= 0 && !isFading) { isFading = true; SimpleTween tweenOut = new SimpleTween(); - HashSet mats = new HashSet(); - foreach (MeshRenderer mr in GetComponentsInChildren()) - { - mats.Add(mr.material); - } tweenOut.Init(v => { foreach (Material m in mats) diff --git a/FallUnity/Assets/Leaves/Pile.cs b/FallUnity/Assets/Leaves/Pile.cs new file mode 100644 index 0000000..47b81a1 --- /dev/null +++ b/FallUnity/Assets/Leaves/Pile.cs @@ -0,0 +1,16 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Pile : MonoBehaviour { + public int NumLeaves = 0; + // Use this for initialization + void Start () { + + } + + // Update is called once per frame + void Update () { + + } +} diff --git a/Build/fall_Data/Managed/Assembly-CSharp.dll b/Build/fall_Data/Managed/Assembly-CSharp.dll index 473b708..7e14020 100644 --- a/Build/fall_Data/Managed/Assembly-CSharp.dll +++ b/Build/fall_Data/Managed/Assembly-CSharp.dll Binary files differ diff --git a/Build/fall_Data/globalgamemanagers b/Build/fall_Data/globalgamemanagers index 4e34461..e79341a 100644 --- a/Build/fall_Data/globalgamemanagers +++ b/Build/fall_Data/globalgamemanagers Binary files differ diff --git a/Build/fall_Data/globalgamemanagers.assets b/Build/fall_Data/globalgamemanagers.assets index f90a19e..8cb05c1 100644 --- a/Build/fall_Data/globalgamemanagers.assets +++ b/Build/fall_Data/globalgamemanagers.assets Binary files differ diff --git a/Build/fall_Data/level0 b/Build/fall_Data/level0 index f49aed1..4a45106 100644 --- a/Build/fall_Data/level0 +++ b/Build/fall_Data/level0 Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets b/Build/fall_Data/sharedassets0.assets index da4c84e..3e933fc 100644 --- a/Build/fall_Data/sharedassets0.assets +++ b/Build/fall_Data/sharedassets0.assets Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets.resS b/Build/fall_Data/sharedassets0.assets.resS index 811ed41..091e899 100644 --- a/Build/fall_Data/sharedassets0.assets.resS +++ b/Build/fall_Data/sharedassets0.assets.resS Binary files differ diff --git a/FallUnity/Assets/Game/LeafSpawner.cs b/FallUnity/Assets/Game/LeafSpawner.cs index dd7cba9..beeff78 100644 --- a/FallUnity/Assets/Game/LeafSpawner.cs +++ b/FallUnity/Assets/Game/LeafSpawner.cs @@ -22,11 +22,13 @@ time += Time.deltaTime; while (time > interval) { + time -= interval; if (leafHandler != null && leafHandler.NumLeaves < leafHandler.MaxLeaves) - { - time -= interval; - Vector2 offset = Random.insideUnitCircle; - Vector3 point = transform.position + new Vector3(offset.x * Radius, 0, offset.y * Radius); + { + float angle = UnityEngine.Random.Range(0, Mathf.PI * 2); + float r = UnityEngine.Random.Range(0, Radius); + + Vector3 point = transform.position + new Vector3(Mathf.Sin(angle) * r, 0, Mathf.Cos(angle) * r); LeafPhysics leaf = GameObject.Instantiate(Leafs[Random.Range(0, Leafs.Length)]); leaves.Add(leaf); leaf.transform.position = point; diff --git a/FallUnity/Assets/Leaves/LeafHandler.cs b/FallUnity/Assets/Leaves/LeafHandler.cs index f931ce3..8ba3c89 100644 --- a/FallUnity/Assets/Leaves/LeafHandler.cs +++ b/FallUnity/Assets/Leaves/LeafHandler.cs @@ -1,28 +1,183 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class LeafHandler : MonoBehaviour { - private int numLeaves = 0; - public int NumLeaves { get { return numLeaves; } } - public int MaxLeaves = 700; - - public void AddLeaf() +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class LeafHandler : MonoBehaviour { + public int NumLeaves = 0; + public int MaxLeaves = 700; + + private HashSet leafs = new HashSet(); + + public void AddLeaf(LeafPhysics l) { - numLeaves++; - } - - public void RemoveLeaf() - { - numLeaves--; + leafs.Add(l); + NumLeaves = leafs.Count; } + + public void RemoveLeaf(LeafPhysics l) + { + leafs.Remove(l); + NumLeaves = leafs.Count; + } + + private SimpleTimer timer; + private SimpleTween tween; // Use this for initialization - void Start () { - - } - - // Update is called once per frame - void Update () { - - } -} + void Start () { + timer = new SimpleTimer(); + tween = new SimpleTween(); + //WaitForNextEvent(); + PickNextEvent(); + } + + private void WaitForNextEvent() + { + timer.Start(UnityEngine.Random.Range(7.0f, 20.0f), PickNextEvent); + } + + private Vector3 windForce = new Vector3(); + private Vector2 whirlwindCenter = new Vector3(); + private float whirlwindRadius = 0; + private float whirlwindForce = 0; + private float whirlwindForceUp = 0; + + private void PickNextEvent() + { + int eventType = UnityEngine.Random.Range(0, 2); + switch (eventType) + { + case 0: + { + // wind + float windAngle = UnityEngine.Random.Range(0, Mathf.PI * 2); + Vector3 windVector = new Vector3(Mathf.Sin(windAngle), 0, Mathf.Cos(windAngle)); + windVector.y = UnityEngine.Random.Range(0.8f, 1.2f); + float windStrength = UnityEngine.Random.Range(0.8f, 1.3f); + float fadeTime = UnityEngine.Random.Range(1.0f, 3.0f); + float windTime = UnityEngine.Random.Range(3.0f, 5.0f); + + Debug.LogError("WIND: V:" + windVector + " S:" + windStrength + " F:" + fadeTime + " T:" + windTime); + + tween.Init(v => + { + windForce = windVector * windStrength * v; + }, SimpleTween.EaseLinear, 0, 1, fadeTime); + tween.OnFinish = () => + { + tween.Init(v => + { + //windForce = windVector * windStrength * (Mathf.Sin(v * 25) + 1) * 0.2f; + }, SimpleTween.EaseLinear, 0, windTime, windTime); + tween.OnFinish = () => + { + tween.Init(v => + { + windForce = windVector * windStrength * v; + }, SimpleTween.EaseLinear, 1, 0, fadeTime); + tween.OnFinish = () => + { + WaitForNextEvent(); + }; + }; + + }; + break; + } + case 1: + { + // whirlwind + whirlwindCenter = UnityEngine.Random.insideUnitCircle * UnityEngine.Random.Range(0, 6.0f); + whirlwindRadius = UnityEngine.Random.Range(3.0f, 4.0f); + float maxWhirlwindForce = UnityEngine.Random.Range(1.0f, 1.6f); + float maxWhirlwindForceUp = UnityEngine.Random.Range(0.3f, 0.8f); + + float fadeTime = UnityEngine.Random.Range(2.0f, 4.0f); + float windTime = UnityEngine.Random.Range(6.0f, 8.0f); + + Debug.LogError("WHIRLWIND: C:" + whirlwindCenter + " R:" + whirlwindRadius + " F:" + maxWhirlwindForce + " U:" + maxWhirlwindForceUp + " F:" + fadeTime + " T:" + windTime); + + tween.Init(v => + { + whirlwindForce = maxWhirlwindForce * v; + whirlwindForceUp = maxWhirlwindForceUp * v; + }, SimpleTween.EaseLinear, 0, 1, fadeTime); + tween.OnFinish = () => + { + tween.Init(v => + { + //windForce = windVector * windStrength * (Mathf.Sin(v * 25) + 1) * 0.2f; + }, SimpleTween.EaseLinear, 0, windTime, windTime); + tween.OnFinish = () => + { + tween.Init(v => + { + whirlwindForce = maxWhirlwindForce * v; + whirlwindForceUp = maxWhirlwindForceUp * v; + }, SimpleTween.EaseLinear, 1, 0, fadeTime); + tween.OnFinish = () => + { + WaitForNextEvent(); + }; + }; + + }; + + break; + } + } + } + + // Update is called once per frame + void Update () { + bool hasWind = windForce.sqrMagnitude > 0.00001f; + bool hasWhirlwind = whirlwindForce > 0; + Vector2 windDir = new Vector2(windForce.x, windForce.y); + windDir.Normalize(); + + float distAway = 9.0f; + + + foreach (LeafPhysics leaf in leafs) + { + if (hasWind && (UnityEngine.Random.Range(0, 1f) < 0.25f || !leaf.Resting)) + { + float amount = Vector2.Dot(new Vector2(leaf.Body.velocity.x, leaf.Body.velocity.z), windDir); + amount = Math.Max(0, Math.Min(1, 8 - amount)); + leaf.Body.AddForce(new Vector3(windForce.x * UnityEngine.Random.Range(0.75f, 1.0f), + windForce.y * UnityEngine.Random.Range(0.9f, 1.0f), + windForce.z * UnityEngine.Random.Range(0.75f, 1.0f)) * Time.deltaTime * 60 * (leaf.Resting ? 3.0f : 0.4f)); + } + Vector2 d = new Vector2(leaf.transform.position.x, leaf.transform.position.z); + + if (hasWhirlwind && (UnityEngine.Random.Range(0, 1f) < 0.15f || !leaf.Resting)) + { + Vector2 offset = new Vector2(leaf.transform.position.x, leaf.transform.position.z) - whirlwindCenter; + Vector2 offsetN = offset.normalized; + float distFrom = offset.magnitude; + + if (distFrom < whirlwindRadius) + { + + Vector2 tangent = new Vector2(-offsetN.y, offsetN.x); + Vector2 force = tangent * (whirlwindRadius - distFrom) * whirlwindForce + offset * -0.9f; + + Vector3 force3D = new Vector3(force.x, whirlwindForceUp * (whirlwindRadius - distFrom + 2), force.y); + + leaf.Body.AddForce(new Vector3(force3D.x * UnityEngine.Random.Range(0.75f, 1.0f), + force3D.y * UnityEngine.Random.Range(0.9f, 1.0f), + force3D.z * UnityEngine.Random.Range(0.75f, 1.0f)) * Time.deltaTime * 60 * (leaf.Resting ? 3.0f : 0.4f)); + + } + + + } + + if (d.magnitude > distAway && !leaf.Resting) + { + //leaf.Body.apply + } + } + + } +} diff --git a/FallUnity/Assets/Leaves/LeafPhysics.cs b/FallUnity/Assets/Leaves/LeafPhysics.cs index 3355523..d59bfba 100755 --- a/FallUnity/Assets/Leaves/LeafPhysics.cs +++ b/FallUnity/Assets/Leaves/LeafPhysics.cs @@ -9,6 +9,10 @@ public Rigidbody Body { get { return body; } } private LeafHandler leafHandler; + + private List mats = new List(); + public IEnumerable Mats { get { return mats; } } + // Use this for initialization void Start () { body = GetComponentInChildren(); @@ -23,18 +27,32 @@ leafHandler = GameObject.FindObjectOfType(); if (leafHandler != null) { - leafHandler.AddLeaf(); + leafHandler.AddLeaf(this); } - deadLifeSpan = UnityEngine.Random.Range(20, 40); + deadLifeSpan = UnityEngine.Random.Range(20, 40.0f); deadLife = deadLifeSpan; + + foreach (MeshRenderer mr in GetComponentsInChildren()) + { + mats.Add(mr.material); + } + + Color c = Color.white; + c.r = UnityEngine.Random.Range(0.6f, 1.0f); + c.g = UnityEngine.Random.Range(0.6f, 1.0f); + c.b = UnityEngine.Random.Range(0.6f, 1.0f); + foreach (Material m in mats) + { + m.color = c; + } } void OnDestroy() { if (leafHandler != null) { - leafHandler.RemoveLeaf(); + leafHandler.RemoveLeaf(this); } } @@ -109,6 +127,17 @@ private bool isFading = false; + public bool Resting = false; + private void FixedUpdate() + { + Resting = false; + } + + private void OnCollisionStay(Collision collision) + { + Resting = collision.contacts.Length > 0 && Mathf.Abs(collision.contacts[0].normal.y) > 0.7f; + } + // Update is called once per frame void Update () { if (!body.isKinematic && body.velocity.sqrMagnitude > 0.01f) @@ -145,16 +174,11 @@ } else { - deadLife -= Time.deltaTime; + deadLife -= Time.deltaTime * (leafHandler.NumLeaves >= leafHandler.MaxLeaves ? 3 : 1); if (deadLife <= 0 && !isFading) { isFading = true; SimpleTween tweenOut = new SimpleTween(); - HashSet mats = new HashSet(); - foreach (MeshRenderer mr in GetComponentsInChildren()) - { - mats.Add(mr.material); - } tweenOut.Init(v => { foreach (Material m in mats) diff --git a/FallUnity/Assets/Leaves/Pile.cs b/FallUnity/Assets/Leaves/Pile.cs new file mode 100644 index 0000000..47b81a1 --- /dev/null +++ b/FallUnity/Assets/Leaves/Pile.cs @@ -0,0 +1,16 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Pile : MonoBehaviour { + public int NumLeaves = 0; + // Use this for initialization + void Start () { + + } + + // Update is called once per frame + void Update () { + + } +} diff --git a/FallUnity/Assets/Leaves/Pile.cs.meta b/FallUnity/Assets/Leaves/Pile.cs.meta new file mode 100644 index 0000000..46f4782 --- /dev/null +++ b/FallUnity/Assets/Leaves/Pile.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 9aba3a790a516f143a6189a050883fe6 +timeCreated: 1572217739 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Build/fall_Data/Managed/Assembly-CSharp.dll b/Build/fall_Data/Managed/Assembly-CSharp.dll index 473b708..7e14020 100644 --- a/Build/fall_Data/Managed/Assembly-CSharp.dll +++ b/Build/fall_Data/Managed/Assembly-CSharp.dll Binary files differ diff --git a/Build/fall_Data/globalgamemanagers b/Build/fall_Data/globalgamemanagers index 4e34461..e79341a 100644 --- a/Build/fall_Data/globalgamemanagers +++ b/Build/fall_Data/globalgamemanagers Binary files differ diff --git a/Build/fall_Data/globalgamemanagers.assets b/Build/fall_Data/globalgamemanagers.assets index f90a19e..8cb05c1 100644 --- a/Build/fall_Data/globalgamemanagers.assets +++ b/Build/fall_Data/globalgamemanagers.assets Binary files differ diff --git a/Build/fall_Data/level0 b/Build/fall_Data/level0 index f49aed1..4a45106 100644 --- a/Build/fall_Data/level0 +++ b/Build/fall_Data/level0 Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets b/Build/fall_Data/sharedassets0.assets index da4c84e..3e933fc 100644 --- a/Build/fall_Data/sharedassets0.assets +++ b/Build/fall_Data/sharedassets0.assets Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets.resS b/Build/fall_Data/sharedassets0.assets.resS index 811ed41..091e899 100644 --- a/Build/fall_Data/sharedassets0.assets.resS +++ b/Build/fall_Data/sharedassets0.assets.resS Binary files differ diff --git a/FallUnity/Assets/Game/LeafSpawner.cs b/FallUnity/Assets/Game/LeafSpawner.cs index dd7cba9..beeff78 100644 --- a/FallUnity/Assets/Game/LeafSpawner.cs +++ b/FallUnity/Assets/Game/LeafSpawner.cs @@ -22,11 +22,13 @@ time += Time.deltaTime; while (time > interval) { + time -= interval; if (leafHandler != null && leafHandler.NumLeaves < leafHandler.MaxLeaves) - { - time -= interval; - Vector2 offset = Random.insideUnitCircle; - Vector3 point = transform.position + new Vector3(offset.x * Radius, 0, offset.y * Radius); + { + float angle = UnityEngine.Random.Range(0, Mathf.PI * 2); + float r = UnityEngine.Random.Range(0, Radius); + + Vector3 point = transform.position + new Vector3(Mathf.Sin(angle) * r, 0, Mathf.Cos(angle) * r); LeafPhysics leaf = GameObject.Instantiate(Leafs[Random.Range(0, Leafs.Length)]); leaves.Add(leaf); leaf.transform.position = point; diff --git a/FallUnity/Assets/Leaves/LeafHandler.cs b/FallUnity/Assets/Leaves/LeafHandler.cs index f931ce3..8ba3c89 100644 --- a/FallUnity/Assets/Leaves/LeafHandler.cs +++ b/FallUnity/Assets/Leaves/LeafHandler.cs @@ -1,28 +1,183 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class LeafHandler : MonoBehaviour { - private int numLeaves = 0; - public int NumLeaves { get { return numLeaves; } } - public int MaxLeaves = 700; - - public void AddLeaf() +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class LeafHandler : MonoBehaviour { + public int NumLeaves = 0; + public int MaxLeaves = 700; + + private HashSet leafs = new HashSet(); + + public void AddLeaf(LeafPhysics l) { - numLeaves++; - } - - public void RemoveLeaf() - { - numLeaves--; + leafs.Add(l); + NumLeaves = leafs.Count; } + + public void RemoveLeaf(LeafPhysics l) + { + leafs.Remove(l); + NumLeaves = leafs.Count; + } + + private SimpleTimer timer; + private SimpleTween tween; // Use this for initialization - void Start () { - - } - - // Update is called once per frame - void Update () { - - } -} + void Start () { + timer = new SimpleTimer(); + tween = new SimpleTween(); + //WaitForNextEvent(); + PickNextEvent(); + } + + private void WaitForNextEvent() + { + timer.Start(UnityEngine.Random.Range(7.0f, 20.0f), PickNextEvent); + } + + private Vector3 windForce = new Vector3(); + private Vector2 whirlwindCenter = new Vector3(); + private float whirlwindRadius = 0; + private float whirlwindForce = 0; + private float whirlwindForceUp = 0; + + private void PickNextEvent() + { + int eventType = UnityEngine.Random.Range(0, 2); + switch (eventType) + { + case 0: + { + // wind + float windAngle = UnityEngine.Random.Range(0, Mathf.PI * 2); + Vector3 windVector = new Vector3(Mathf.Sin(windAngle), 0, Mathf.Cos(windAngle)); + windVector.y = UnityEngine.Random.Range(0.8f, 1.2f); + float windStrength = UnityEngine.Random.Range(0.8f, 1.3f); + float fadeTime = UnityEngine.Random.Range(1.0f, 3.0f); + float windTime = UnityEngine.Random.Range(3.0f, 5.0f); + + Debug.LogError("WIND: V:" + windVector + " S:" + windStrength + " F:" + fadeTime + " T:" + windTime); + + tween.Init(v => + { + windForce = windVector * windStrength * v; + }, SimpleTween.EaseLinear, 0, 1, fadeTime); + tween.OnFinish = () => + { + tween.Init(v => + { + //windForce = windVector * windStrength * (Mathf.Sin(v * 25) + 1) * 0.2f; + }, SimpleTween.EaseLinear, 0, windTime, windTime); + tween.OnFinish = () => + { + tween.Init(v => + { + windForce = windVector * windStrength * v; + }, SimpleTween.EaseLinear, 1, 0, fadeTime); + tween.OnFinish = () => + { + WaitForNextEvent(); + }; + }; + + }; + break; + } + case 1: + { + // whirlwind + whirlwindCenter = UnityEngine.Random.insideUnitCircle * UnityEngine.Random.Range(0, 6.0f); + whirlwindRadius = UnityEngine.Random.Range(3.0f, 4.0f); + float maxWhirlwindForce = UnityEngine.Random.Range(1.0f, 1.6f); + float maxWhirlwindForceUp = UnityEngine.Random.Range(0.3f, 0.8f); + + float fadeTime = UnityEngine.Random.Range(2.0f, 4.0f); + float windTime = UnityEngine.Random.Range(6.0f, 8.0f); + + Debug.LogError("WHIRLWIND: C:" + whirlwindCenter + " R:" + whirlwindRadius + " F:" + maxWhirlwindForce + " U:" + maxWhirlwindForceUp + " F:" + fadeTime + " T:" + windTime); + + tween.Init(v => + { + whirlwindForce = maxWhirlwindForce * v; + whirlwindForceUp = maxWhirlwindForceUp * v; + }, SimpleTween.EaseLinear, 0, 1, fadeTime); + tween.OnFinish = () => + { + tween.Init(v => + { + //windForce = windVector * windStrength * (Mathf.Sin(v * 25) + 1) * 0.2f; + }, SimpleTween.EaseLinear, 0, windTime, windTime); + tween.OnFinish = () => + { + tween.Init(v => + { + whirlwindForce = maxWhirlwindForce * v; + whirlwindForceUp = maxWhirlwindForceUp * v; + }, SimpleTween.EaseLinear, 1, 0, fadeTime); + tween.OnFinish = () => + { + WaitForNextEvent(); + }; + }; + + }; + + break; + } + } + } + + // Update is called once per frame + void Update () { + bool hasWind = windForce.sqrMagnitude > 0.00001f; + bool hasWhirlwind = whirlwindForce > 0; + Vector2 windDir = new Vector2(windForce.x, windForce.y); + windDir.Normalize(); + + float distAway = 9.0f; + + + foreach (LeafPhysics leaf in leafs) + { + if (hasWind && (UnityEngine.Random.Range(0, 1f) < 0.25f || !leaf.Resting)) + { + float amount = Vector2.Dot(new Vector2(leaf.Body.velocity.x, leaf.Body.velocity.z), windDir); + amount = Math.Max(0, Math.Min(1, 8 - amount)); + leaf.Body.AddForce(new Vector3(windForce.x * UnityEngine.Random.Range(0.75f, 1.0f), + windForce.y * UnityEngine.Random.Range(0.9f, 1.0f), + windForce.z * UnityEngine.Random.Range(0.75f, 1.0f)) * Time.deltaTime * 60 * (leaf.Resting ? 3.0f : 0.4f)); + } + Vector2 d = new Vector2(leaf.transform.position.x, leaf.transform.position.z); + + if (hasWhirlwind && (UnityEngine.Random.Range(0, 1f) < 0.15f || !leaf.Resting)) + { + Vector2 offset = new Vector2(leaf.transform.position.x, leaf.transform.position.z) - whirlwindCenter; + Vector2 offsetN = offset.normalized; + float distFrom = offset.magnitude; + + if (distFrom < whirlwindRadius) + { + + Vector2 tangent = new Vector2(-offsetN.y, offsetN.x); + Vector2 force = tangent * (whirlwindRadius - distFrom) * whirlwindForce + offset * -0.9f; + + Vector3 force3D = new Vector3(force.x, whirlwindForceUp * (whirlwindRadius - distFrom + 2), force.y); + + leaf.Body.AddForce(new Vector3(force3D.x * UnityEngine.Random.Range(0.75f, 1.0f), + force3D.y * UnityEngine.Random.Range(0.9f, 1.0f), + force3D.z * UnityEngine.Random.Range(0.75f, 1.0f)) * Time.deltaTime * 60 * (leaf.Resting ? 3.0f : 0.4f)); + + } + + + } + + if (d.magnitude > distAway && !leaf.Resting) + { + //leaf.Body.apply + } + } + + } +} diff --git a/FallUnity/Assets/Leaves/LeafPhysics.cs b/FallUnity/Assets/Leaves/LeafPhysics.cs index 3355523..d59bfba 100755 --- a/FallUnity/Assets/Leaves/LeafPhysics.cs +++ b/FallUnity/Assets/Leaves/LeafPhysics.cs @@ -9,6 +9,10 @@ public Rigidbody Body { get { return body; } } private LeafHandler leafHandler; + + private List mats = new List(); + public IEnumerable Mats { get { return mats; } } + // Use this for initialization void Start () { body = GetComponentInChildren(); @@ -23,18 +27,32 @@ leafHandler = GameObject.FindObjectOfType(); if (leafHandler != null) { - leafHandler.AddLeaf(); + leafHandler.AddLeaf(this); } - deadLifeSpan = UnityEngine.Random.Range(20, 40); + deadLifeSpan = UnityEngine.Random.Range(20, 40.0f); deadLife = deadLifeSpan; + + foreach (MeshRenderer mr in GetComponentsInChildren()) + { + mats.Add(mr.material); + } + + Color c = Color.white; + c.r = UnityEngine.Random.Range(0.6f, 1.0f); + c.g = UnityEngine.Random.Range(0.6f, 1.0f); + c.b = UnityEngine.Random.Range(0.6f, 1.0f); + foreach (Material m in mats) + { + m.color = c; + } } void OnDestroy() { if (leafHandler != null) { - leafHandler.RemoveLeaf(); + leafHandler.RemoveLeaf(this); } } @@ -109,6 +127,17 @@ private bool isFading = false; + public bool Resting = false; + private void FixedUpdate() + { + Resting = false; + } + + private void OnCollisionStay(Collision collision) + { + Resting = collision.contacts.Length > 0 && Mathf.Abs(collision.contacts[0].normal.y) > 0.7f; + } + // Update is called once per frame void Update () { if (!body.isKinematic && body.velocity.sqrMagnitude > 0.01f) @@ -145,16 +174,11 @@ } else { - deadLife -= Time.deltaTime; + deadLife -= Time.deltaTime * (leafHandler.NumLeaves >= leafHandler.MaxLeaves ? 3 : 1); if (deadLife <= 0 && !isFading) { isFading = true; SimpleTween tweenOut = new SimpleTween(); - HashSet mats = new HashSet(); - foreach (MeshRenderer mr in GetComponentsInChildren()) - { - mats.Add(mr.material); - } tweenOut.Init(v => { foreach (Material m in mats) diff --git a/FallUnity/Assets/Leaves/Pile.cs b/FallUnity/Assets/Leaves/Pile.cs new file mode 100644 index 0000000..47b81a1 --- /dev/null +++ b/FallUnity/Assets/Leaves/Pile.cs @@ -0,0 +1,16 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Pile : MonoBehaviour { + public int NumLeaves = 0; + // Use this for initialization + void Start () { + + } + + // Update is called once per frame + void Update () { + + } +} diff --git a/FallUnity/Assets/Leaves/Pile.cs.meta b/FallUnity/Assets/Leaves/Pile.cs.meta new file mode 100644 index 0000000..46f4782 --- /dev/null +++ b/FallUnity/Assets/Leaves/Pile.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 9aba3a790a516f143a6189a050883fe6 +timeCreated: 1572217739 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/FallUnity/Assets/Leaves/Pile.prefab b/FallUnity/Assets/Leaves/Pile.prefab index c9e6823..7399566 100644 --- a/FallUnity/Assets/Leaves/Pile.prefab +++ b/FallUnity/Assets/Leaves/Pile.prefab @@ -46,7 +46,7 @@ m_IsActive: 1 --- !u!1 &1455629288405468 GameObject: - m_ObjectHideFlags: 0 + m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} serializedVersion: 5 @@ -60,13 +60,28 @@ m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!1 &1865097145533800 +--- !u!1 &1676669835933754 GameObject: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} serializedVersion: 5 m_Component: + - component: {fileID: 4516590634453678} + m_Layer: 0 + m_Name: PileHolder + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!1 &1865097145533800 +GameObject: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 5 + m_Component: - component: {fileID: 4637029664340020} m_Layer: 0 m_Name: Mesh @@ -81,12 +96,11 @@ m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1430576817403556} - m_LocalRotation: {x: 0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -0.6, y: -1.1, z: 4.45} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: -1.13, y: 6.12, z: 8.16} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - - {fileID: 4637029664340020} - - {fileID: 4794401915724672} + - {fileID: 4516590634453678} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -103,18 +117,33 @@ m_Father: {fileID: 4637029664340020} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!4 &4516590634453678 +Transform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1676669835933754} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 4637029664340020} + - {fileID: 4794401915724672} + m_Father: {fileID: 4028432306176728} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!4 &4637029664340020 Transform: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1865097145533800} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0.5187102, y: 0.51870996, z: 0.51870996} m_Children: - {fileID: 4097242592220890} - m_Father: {fileID: 4028432306176728} + m_Father: {fileID: 4516590634453678} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!4 &4794401915724672 @@ -123,11 +152,11 @@ m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1455629288405468} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0.5187102, y: 0.51870996, z: 0.51870996} m_Children: [] - m_Father: {fileID: 4028432306176728} + m_Father: {fileID: 4516590634453678} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!23 &23658430294834434 diff --git a/Build/fall_Data/Managed/Assembly-CSharp.dll b/Build/fall_Data/Managed/Assembly-CSharp.dll index 473b708..7e14020 100644 --- a/Build/fall_Data/Managed/Assembly-CSharp.dll +++ b/Build/fall_Data/Managed/Assembly-CSharp.dll Binary files differ diff --git a/Build/fall_Data/globalgamemanagers b/Build/fall_Data/globalgamemanagers index 4e34461..e79341a 100644 --- a/Build/fall_Data/globalgamemanagers +++ b/Build/fall_Data/globalgamemanagers Binary files differ diff --git a/Build/fall_Data/globalgamemanagers.assets b/Build/fall_Data/globalgamemanagers.assets index f90a19e..8cb05c1 100644 --- a/Build/fall_Data/globalgamemanagers.assets +++ b/Build/fall_Data/globalgamemanagers.assets Binary files differ diff --git a/Build/fall_Data/level0 b/Build/fall_Data/level0 index f49aed1..4a45106 100644 --- a/Build/fall_Data/level0 +++ b/Build/fall_Data/level0 Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets b/Build/fall_Data/sharedassets0.assets index da4c84e..3e933fc 100644 --- a/Build/fall_Data/sharedassets0.assets +++ b/Build/fall_Data/sharedassets0.assets Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets.resS b/Build/fall_Data/sharedassets0.assets.resS index 811ed41..091e899 100644 --- a/Build/fall_Data/sharedassets0.assets.resS +++ b/Build/fall_Data/sharedassets0.assets.resS Binary files differ diff --git a/FallUnity/Assets/Game/LeafSpawner.cs b/FallUnity/Assets/Game/LeafSpawner.cs index dd7cba9..beeff78 100644 --- a/FallUnity/Assets/Game/LeafSpawner.cs +++ b/FallUnity/Assets/Game/LeafSpawner.cs @@ -22,11 +22,13 @@ time += Time.deltaTime; while (time > interval) { + time -= interval; if (leafHandler != null && leafHandler.NumLeaves < leafHandler.MaxLeaves) - { - time -= interval; - Vector2 offset = Random.insideUnitCircle; - Vector3 point = transform.position + new Vector3(offset.x * Radius, 0, offset.y * Radius); + { + float angle = UnityEngine.Random.Range(0, Mathf.PI * 2); + float r = UnityEngine.Random.Range(0, Radius); + + Vector3 point = transform.position + new Vector3(Mathf.Sin(angle) * r, 0, Mathf.Cos(angle) * r); LeafPhysics leaf = GameObject.Instantiate(Leafs[Random.Range(0, Leafs.Length)]); leaves.Add(leaf); leaf.transform.position = point; diff --git a/FallUnity/Assets/Leaves/LeafHandler.cs b/FallUnity/Assets/Leaves/LeafHandler.cs index f931ce3..8ba3c89 100644 --- a/FallUnity/Assets/Leaves/LeafHandler.cs +++ b/FallUnity/Assets/Leaves/LeafHandler.cs @@ -1,28 +1,183 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class LeafHandler : MonoBehaviour { - private int numLeaves = 0; - public int NumLeaves { get { return numLeaves; } } - public int MaxLeaves = 700; - - public void AddLeaf() +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class LeafHandler : MonoBehaviour { + public int NumLeaves = 0; + public int MaxLeaves = 700; + + private HashSet leafs = new HashSet(); + + public void AddLeaf(LeafPhysics l) { - numLeaves++; - } - - public void RemoveLeaf() - { - numLeaves--; + leafs.Add(l); + NumLeaves = leafs.Count; } + + public void RemoveLeaf(LeafPhysics l) + { + leafs.Remove(l); + NumLeaves = leafs.Count; + } + + private SimpleTimer timer; + private SimpleTween tween; // Use this for initialization - void Start () { - - } - - // Update is called once per frame - void Update () { - - } -} + void Start () { + timer = new SimpleTimer(); + tween = new SimpleTween(); + //WaitForNextEvent(); + PickNextEvent(); + } + + private void WaitForNextEvent() + { + timer.Start(UnityEngine.Random.Range(7.0f, 20.0f), PickNextEvent); + } + + private Vector3 windForce = new Vector3(); + private Vector2 whirlwindCenter = new Vector3(); + private float whirlwindRadius = 0; + private float whirlwindForce = 0; + private float whirlwindForceUp = 0; + + private void PickNextEvent() + { + int eventType = UnityEngine.Random.Range(0, 2); + switch (eventType) + { + case 0: + { + // wind + float windAngle = UnityEngine.Random.Range(0, Mathf.PI * 2); + Vector3 windVector = new Vector3(Mathf.Sin(windAngle), 0, Mathf.Cos(windAngle)); + windVector.y = UnityEngine.Random.Range(0.8f, 1.2f); + float windStrength = UnityEngine.Random.Range(0.8f, 1.3f); + float fadeTime = UnityEngine.Random.Range(1.0f, 3.0f); + float windTime = UnityEngine.Random.Range(3.0f, 5.0f); + + Debug.LogError("WIND: V:" + windVector + " S:" + windStrength + " F:" + fadeTime + " T:" + windTime); + + tween.Init(v => + { + windForce = windVector * windStrength * v; + }, SimpleTween.EaseLinear, 0, 1, fadeTime); + tween.OnFinish = () => + { + tween.Init(v => + { + //windForce = windVector * windStrength * (Mathf.Sin(v * 25) + 1) * 0.2f; + }, SimpleTween.EaseLinear, 0, windTime, windTime); + tween.OnFinish = () => + { + tween.Init(v => + { + windForce = windVector * windStrength * v; + }, SimpleTween.EaseLinear, 1, 0, fadeTime); + tween.OnFinish = () => + { + WaitForNextEvent(); + }; + }; + + }; + break; + } + case 1: + { + // whirlwind + whirlwindCenter = UnityEngine.Random.insideUnitCircle * UnityEngine.Random.Range(0, 6.0f); + whirlwindRadius = UnityEngine.Random.Range(3.0f, 4.0f); + float maxWhirlwindForce = UnityEngine.Random.Range(1.0f, 1.6f); + float maxWhirlwindForceUp = UnityEngine.Random.Range(0.3f, 0.8f); + + float fadeTime = UnityEngine.Random.Range(2.0f, 4.0f); + float windTime = UnityEngine.Random.Range(6.0f, 8.0f); + + Debug.LogError("WHIRLWIND: C:" + whirlwindCenter + " R:" + whirlwindRadius + " F:" + maxWhirlwindForce + " U:" + maxWhirlwindForceUp + " F:" + fadeTime + " T:" + windTime); + + tween.Init(v => + { + whirlwindForce = maxWhirlwindForce * v; + whirlwindForceUp = maxWhirlwindForceUp * v; + }, SimpleTween.EaseLinear, 0, 1, fadeTime); + tween.OnFinish = () => + { + tween.Init(v => + { + //windForce = windVector * windStrength * (Mathf.Sin(v * 25) + 1) * 0.2f; + }, SimpleTween.EaseLinear, 0, windTime, windTime); + tween.OnFinish = () => + { + tween.Init(v => + { + whirlwindForce = maxWhirlwindForce * v; + whirlwindForceUp = maxWhirlwindForceUp * v; + }, SimpleTween.EaseLinear, 1, 0, fadeTime); + tween.OnFinish = () => + { + WaitForNextEvent(); + }; + }; + + }; + + break; + } + } + } + + // Update is called once per frame + void Update () { + bool hasWind = windForce.sqrMagnitude > 0.00001f; + bool hasWhirlwind = whirlwindForce > 0; + Vector2 windDir = new Vector2(windForce.x, windForce.y); + windDir.Normalize(); + + float distAway = 9.0f; + + + foreach (LeafPhysics leaf in leafs) + { + if (hasWind && (UnityEngine.Random.Range(0, 1f) < 0.25f || !leaf.Resting)) + { + float amount = Vector2.Dot(new Vector2(leaf.Body.velocity.x, leaf.Body.velocity.z), windDir); + amount = Math.Max(0, Math.Min(1, 8 - amount)); + leaf.Body.AddForce(new Vector3(windForce.x * UnityEngine.Random.Range(0.75f, 1.0f), + windForce.y * UnityEngine.Random.Range(0.9f, 1.0f), + windForce.z * UnityEngine.Random.Range(0.75f, 1.0f)) * Time.deltaTime * 60 * (leaf.Resting ? 3.0f : 0.4f)); + } + Vector2 d = new Vector2(leaf.transform.position.x, leaf.transform.position.z); + + if (hasWhirlwind && (UnityEngine.Random.Range(0, 1f) < 0.15f || !leaf.Resting)) + { + Vector2 offset = new Vector2(leaf.transform.position.x, leaf.transform.position.z) - whirlwindCenter; + Vector2 offsetN = offset.normalized; + float distFrom = offset.magnitude; + + if (distFrom < whirlwindRadius) + { + + Vector2 tangent = new Vector2(-offsetN.y, offsetN.x); + Vector2 force = tangent * (whirlwindRadius - distFrom) * whirlwindForce + offset * -0.9f; + + Vector3 force3D = new Vector3(force.x, whirlwindForceUp * (whirlwindRadius - distFrom + 2), force.y); + + leaf.Body.AddForce(new Vector3(force3D.x * UnityEngine.Random.Range(0.75f, 1.0f), + force3D.y * UnityEngine.Random.Range(0.9f, 1.0f), + force3D.z * UnityEngine.Random.Range(0.75f, 1.0f)) * Time.deltaTime * 60 * (leaf.Resting ? 3.0f : 0.4f)); + + } + + + } + + if (d.magnitude > distAway && !leaf.Resting) + { + //leaf.Body.apply + } + } + + } +} diff --git a/FallUnity/Assets/Leaves/LeafPhysics.cs b/FallUnity/Assets/Leaves/LeafPhysics.cs index 3355523..d59bfba 100755 --- a/FallUnity/Assets/Leaves/LeafPhysics.cs +++ b/FallUnity/Assets/Leaves/LeafPhysics.cs @@ -9,6 +9,10 @@ public Rigidbody Body { get { return body; } } private LeafHandler leafHandler; + + private List mats = new List(); + public IEnumerable Mats { get { return mats; } } + // Use this for initialization void Start () { body = GetComponentInChildren(); @@ -23,18 +27,32 @@ leafHandler = GameObject.FindObjectOfType(); if (leafHandler != null) { - leafHandler.AddLeaf(); + leafHandler.AddLeaf(this); } - deadLifeSpan = UnityEngine.Random.Range(20, 40); + deadLifeSpan = UnityEngine.Random.Range(20, 40.0f); deadLife = deadLifeSpan; + + foreach (MeshRenderer mr in GetComponentsInChildren()) + { + mats.Add(mr.material); + } + + Color c = Color.white; + c.r = UnityEngine.Random.Range(0.6f, 1.0f); + c.g = UnityEngine.Random.Range(0.6f, 1.0f); + c.b = UnityEngine.Random.Range(0.6f, 1.0f); + foreach (Material m in mats) + { + m.color = c; + } } void OnDestroy() { if (leafHandler != null) { - leafHandler.RemoveLeaf(); + leafHandler.RemoveLeaf(this); } } @@ -109,6 +127,17 @@ private bool isFading = false; + public bool Resting = false; + private void FixedUpdate() + { + Resting = false; + } + + private void OnCollisionStay(Collision collision) + { + Resting = collision.contacts.Length > 0 && Mathf.Abs(collision.contacts[0].normal.y) > 0.7f; + } + // Update is called once per frame void Update () { if (!body.isKinematic && body.velocity.sqrMagnitude > 0.01f) @@ -145,16 +174,11 @@ } else { - deadLife -= Time.deltaTime; + deadLife -= Time.deltaTime * (leafHandler.NumLeaves >= leafHandler.MaxLeaves ? 3 : 1); if (deadLife <= 0 && !isFading) { isFading = true; SimpleTween tweenOut = new SimpleTween(); - HashSet mats = new HashSet(); - foreach (MeshRenderer mr in GetComponentsInChildren()) - { - mats.Add(mr.material); - } tweenOut.Init(v => { foreach (Material m in mats) diff --git a/FallUnity/Assets/Leaves/Pile.cs b/FallUnity/Assets/Leaves/Pile.cs new file mode 100644 index 0000000..47b81a1 --- /dev/null +++ b/FallUnity/Assets/Leaves/Pile.cs @@ -0,0 +1,16 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Pile : MonoBehaviour { + public int NumLeaves = 0; + // Use this for initialization + void Start () { + + } + + // Update is called once per frame + void Update () { + + } +} diff --git a/FallUnity/Assets/Leaves/Pile.cs.meta b/FallUnity/Assets/Leaves/Pile.cs.meta new file mode 100644 index 0000000..46f4782 --- /dev/null +++ b/FallUnity/Assets/Leaves/Pile.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 9aba3a790a516f143a6189a050883fe6 +timeCreated: 1572217739 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/FallUnity/Assets/Leaves/Pile.prefab b/FallUnity/Assets/Leaves/Pile.prefab index c9e6823..7399566 100644 --- a/FallUnity/Assets/Leaves/Pile.prefab +++ b/FallUnity/Assets/Leaves/Pile.prefab @@ -46,7 +46,7 @@ m_IsActive: 1 --- !u!1 &1455629288405468 GameObject: - m_ObjectHideFlags: 0 + m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} serializedVersion: 5 @@ -60,13 +60,28 @@ m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!1 &1865097145533800 +--- !u!1 &1676669835933754 GameObject: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} serializedVersion: 5 m_Component: + - component: {fileID: 4516590634453678} + m_Layer: 0 + m_Name: PileHolder + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!1 &1865097145533800 +GameObject: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 5 + m_Component: - component: {fileID: 4637029664340020} m_Layer: 0 m_Name: Mesh @@ -81,12 +96,11 @@ m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1430576817403556} - m_LocalRotation: {x: 0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -0.6, y: -1.1, z: 4.45} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: -1.13, y: 6.12, z: 8.16} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - - {fileID: 4637029664340020} - - {fileID: 4794401915724672} + - {fileID: 4516590634453678} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -103,18 +117,33 @@ m_Father: {fileID: 4637029664340020} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!4 &4516590634453678 +Transform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1676669835933754} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 4637029664340020} + - {fileID: 4794401915724672} + m_Father: {fileID: 4028432306176728} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!4 &4637029664340020 Transform: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1865097145533800} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0.5187102, y: 0.51870996, z: 0.51870996} m_Children: - {fileID: 4097242592220890} - m_Father: {fileID: 4028432306176728} + m_Father: {fileID: 4516590634453678} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!4 &4794401915724672 @@ -123,11 +152,11 @@ m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1455629288405468} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0.5187102, y: 0.51870996, z: 0.51870996} m_Children: [] - m_Father: {fileID: 4028432306176728} + m_Father: {fileID: 4516590634453678} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!23 &23658430294834434 diff --git a/FallUnity/Assets/Player/Player.prefab b/FallUnity/Assets/Player/Player.prefab index c9796b0..c6f5428 100644 --- a/FallUnity/Assets/Player/Player.prefab +++ b/FallUnity/Assets/Player/Player.prefab @@ -236,7 +236,9 @@ RakeBackTime: 0.15 RakeReachDist: 0.7 RakeReachRadius: 0.8 - RakeFlyForce: 100 + RakeFlyForce: 2.02 + PilePrefab: {fileID: 1430576817403556, guid: d6cf61ddfecafa14991e99ec6f1e33f0, type: 2} + PileSearchRadius: 0.7 --- !u!114 &114917061756029764 MonoBehaviour: m_ObjectHideFlags: 1 diff --git a/Build/fall_Data/Managed/Assembly-CSharp.dll b/Build/fall_Data/Managed/Assembly-CSharp.dll index 473b708..7e14020 100644 --- a/Build/fall_Data/Managed/Assembly-CSharp.dll +++ b/Build/fall_Data/Managed/Assembly-CSharp.dll Binary files differ diff --git a/Build/fall_Data/globalgamemanagers b/Build/fall_Data/globalgamemanagers index 4e34461..e79341a 100644 --- a/Build/fall_Data/globalgamemanagers +++ b/Build/fall_Data/globalgamemanagers Binary files differ diff --git a/Build/fall_Data/globalgamemanagers.assets b/Build/fall_Data/globalgamemanagers.assets index f90a19e..8cb05c1 100644 --- a/Build/fall_Data/globalgamemanagers.assets +++ b/Build/fall_Data/globalgamemanagers.assets Binary files differ diff --git a/Build/fall_Data/level0 b/Build/fall_Data/level0 index f49aed1..4a45106 100644 --- a/Build/fall_Data/level0 +++ b/Build/fall_Data/level0 Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets b/Build/fall_Data/sharedassets0.assets index da4c84e..3e933fc 100644 --- a/Build/fall_Data/sharedassets0.assets +++ b/Build/fall_Data/sharedassets0.assets Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets.resS b/Build/fall_Data/sharedassets0.assets.resS index 811ed41..091e899 100644 --- a/Build/fall_Data/sharedassets0.assets.resS +++ b/Build/fall_Data/sharedassets0.assets.resS Binary files differ diff --git a/FallUnity/Assets/Game/LeafSpawner.cs b/FallUnity/Assets/Game/LeafSpawner.cs index dd7cba9..beeff78 100644 --- a/FallUnity/Assets/Game/LeafSpawner.cs +++ b/FallUnity/Assets/Game/LeafSpawner.cs @@ -22,11 +22,13 @@ time += Time.deltaTime; while (time > interval) { + time -= interval; if (leafHandler != null && leafHandler.NumLeaves < leafHandler.MaxLeaves) - { - time -= interval; - Vector2 offset = Random.insideUnitCircle; - Vector3 point = transform.position + new Vector3(offset.x * Radius, 0, offset.y * Radius); + { + float angle = UnityEngine.Random.Range(0, Mathf.PI * 2); + float r = UnityEngine.Random.Range(0, Radius); + + Vector3 point = transform.position + new Vector3(Mathf.Sin(angle) * r, 0, Mathf.Cos(angle) * r); LeafPhysics leaf = GameObject.Instantiate(Leafs[Random.Range(0, Leafs.Length)]); leaves.Add(leaf); leaf.transform.position = point; diff --git a/FallUnity/Assets/Leaves/LeafHandler.cs b/FallUnity/Assets/Leaves/LeafHandler.cs index f931ce3..8ba3c89 100644 --- a/FallUnity/Assets/Leaves/LeafHandler.cs +++ b/FallUnity/Assets/Leaves/LeafHandler.cs @@ -1,28 +1,183 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class LeafHandler : MonoBehaviour { - private int numLeaves = 0; - public int NumLeaves { get { return numLeaves; } } - public int MaxLeaves = 700; - - public void AddLeaf() +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class LeafHandler : MonoBehaviour { + public int NumLeaves = 0; + public int MaxLeaves = 700; + + private HashSet leafs = new HashSet(); + + public void AddLeaf(LeafPhysics l) { - numLeaves++; - } - - public void RemoveLeaf() - { - numLeaves--; + leafs.Add(l); + NumLeaves = leafs.Count; } + + public void RemoveLeaf(LeafPhysics l) + { + leafs.Remove(l); + NumLeaves = leafs.Count; + } + + private SimpleTimer timer; + private SimpleTween tween; // Use this for initialization - void Start () { - - } - - // Update is called once per frame - void Update () { - - } -} + void Start () { + timer = new SimpleTimer(); + tween = new SimpleTween(); + //WaitForNextEvent(); + PickNextEvent(); + } + + private void WaitForNextEvent() + { + timer.Start(UnityEngine.Random.Range(7.0f, 20.0f), PickNextEvent); + } + + private Vector3 windForce = new Vector3(); + private Vector2 whirlwindCenter = new Vector3(); + private float whirlwindRadius = 0; + private float whirlwindForce = 0; + private float whirlwindForceUp = 0; + + private void PickNextEvent() + { + int eventType = UnityEngine.Random.Range(0, 2); + switch (eventType) + { + case 0: + { + // wind + float windAngle = UnityEngine.Random.Range(0, Mathf.PI * 2); + Vector3 windVector = new Vector3(Mathf.Sin(windAngle), 0, Mathf.Cos(windAngle)); + windVector.y = UnityEngine.Random.Range(0.8f, 1.2f); + float windStrength = UnityEngine.Random.Range(0.8f, 1.3f); + float fadeTime = UnityEngine.Random.Range(1.0f, 3.0f); + float windTime = UnityEngine.Random.Range(3.0f, 5.0f); + + Debug.LogError("WIND: V:" + windVector + " S:" + windStrength + " F:" + fadeTime + " T:" + windTime); + + tween.Init(v => + { + windForce = windVector * windStrength * v; + }, SimpleTween.EaseLinear, 0, 1, fadeTime); + tween.OnFinish = () => + { + tween.Init(v => + { + //windForce = windVector * windStrength * (Mathf.Sin(v * 25) + 1) * 0.2f; + }, SimpleTween.EaseLinear, 0, windTime, windTime); + tween.OnFinish = () => + { + tween.Init(v => + { + windForce = windVector * windStrength * v; + }, SimpleTween.EaseLinear, 1, 0, fadeTime); + tween.OnFinish = () => + { + WaitForNextEvent(); + }; + }; + + }; + break; + } + case 1: + { + // whirlwind + whirlwindCenter = UnityEngine.Random.insideUnitCircle * UnityEngine.Random.Range(0, 6.0f); + whirlwindRadius = UnityEngine.Random.Range(3.0f, 4.0f); + float maxWhirlwindForce = UnityEngine.Random.Range(1.0f, 1.6f); + float maxWhirlwindForceUp = UnityEngine.Random.Range(0.3f, 0.8f); + + float fadeTime = UnityEngine.Random.Range(2.0f, 4.0f); + float windTime = UnityEngine.Random.Range(6.0f, 8.0f); + + Debug.LogError("WHIRLWIND: C:" + whirlwindCenter + " R:" + whirlwindRadius + " F:" + maxWhirlwindForce + " U:" + maxWhirlwindForceUp + " F:" + fadeTime + " T:" + windTime); + + tween.Init(v => + { + whirlwindForce = maxWhirlwindForce * v; + whirlwindForceUp = maxWhirlwindForceUp * v; + }, SimpleTween.EaseLinear, 0, 1, fadeTime); + tween.OnFinish = () => + { + tween.Init(v => + { + //windForce = windVector * windStrength * (Mathf.Sin(v * 25) + 1) * 0.2f; + }, SimpleTween.EaseLinear, 0, windTime, windTime); + tween.OnFinish = () => + { + tween.Init(v => + { + whirlwindForce = maxWhirlwindForce * v; + whirlwindForceUp = maxWhirlwindForceUp * v; + }, SimpleTween.EaseLinear, 1, 0, fadeTime); + tween.OnFinish = () => + { + WaitForNextEvent(); + }; + }; + + }; + + break; + } + } + } + + // Update is called once per frame + void Update () { + bool hasWind = windForce.sqrMagnitude > 0.00001f; + bool hasWhirlwind = whirlwindForce > 0; + Vector2 windDir = new Vector2(windForce.x, windForce.y); + windDir.Normalize(); + + float distAway = 9.0f; + + + foreach (LeafPhysics leaf in leafs) + { + if (hasWind && (UnityEngine.Random.Range(0, 1f) < 0.25f || !leaf.Resting)) + { + float amount = Vector2.Dot(new Vector2(leaf.Body.velocity.x, leaf.Body.velocity.z), windDir); + amount = Math.Max(0, Math.Min(1, 8 - amount)); + leaf.Body.AddForce(new Vector3(windForce.x * UnityEngine.Random.Range(0.75f, 1.0f), + windForce.y * UnityEngine.Random.Range(0.9f, 1.0f), + windForce.z * UnityEngine.Random.Range(0.75f, 1.0f)) * Time.deltaTime * 60 * (leaf.Resting ? 3.0f : 0.4f)); + } + Vector2 d = new Vector2(leaf.transform.position.x, leaf.transform.position.z); + + if (hasWhirlwind && (UnityEngine.Random.Range(0, 1f) < 0.15f || !leaf.Resting)) + { + Vector2 offset = new Vector2(leaf.transform.position.x, leaf.transform.position.z) - whirlwindCenter; + Vector2 offsetN = offset.normalized; + float distFrom = offset.magnitude; + + if (distFrom < whirlwindRadius) + { + + Vector2 tangent = new Vector2(-offsetN.y, offsetN.x); + Vector2 force = tangent * (whirlwindRadius - distFrom) * whirlwindForce + offset * -0.9f; + + Vector3 force3D = new Vector3(force.x, whirlwindForceUp * (whirlwindRadius - distFrom + 2), force.y); + + leaf.Body.AddForce(new Vector3(force3D.x * UnityEngine.Random.Range(0.75f, 1.0f), + force3D.y * UnityEngine.Random.Range(0.9f, 1.0f), + force3D.z * UnityEngine.Random.Range(0.75f, 1.0f)) * Time.deltaTime * 60 * (leaf.Resting ? 3.0f : 0.4f)); + + } + + + } + + if (d.magnitude > distAway && !leaf.Resting) + { + //leaf.Body.apply + } + } + + } +} diff --git a/FallUnity/Assets/Leaves/LeafPhysics.cs b/FallUnity/Assets/Leaves/LeafPhysics.cs index 3355523..d59bfba 100755 --- a/FallUnity/Assets/Leaves/LeafPhysics.cs +++ b/FallUnity/Assets/Leaves/LeafPhysics.cs @@ -9,6 +9,10 @@ public Rigidbody Body { get { return body; } } private LeafHandler leafHandler; + + private List mats = new List(); + public IEnumerable Mats { get { return mats; } } + // Use this for initialization void Start () { body = GetComponentInChildren(); @@ -23,18 +27,32 @@ leafHandler = GameObject.FindObjectOfType(); if (leafHandler != null) { - leafHandler.AddLeaf(); + leafHandler.AddLeaf(this); } - deadLifeSpan = UnityEngine.Random.Range(20, 40); + deadLifeSpan = UnityEngine.Random.Range(20, 40.0f); deadLife = deadLifeSpan; + + foreach (MeshRenderer mr in GetComponentsInChildren()) + { + mats.Add(mr.material); + } + + Color c = Color.white; + c.r = UnityEngine.Random.Range(0.6f, 1.0f); + c.g = UnityEngine.Random.Range(0.6f, 1.0f); + c.b = UnityEngine.Random.Range(0.6f, 1.0f); + foreach (Material m in mats) + { + m.color = c; + } } void OnDestroy() { if (leafHandler != null) { - leafHandler.RemoveLeaf(); + leafHandler.RemoveLeaf(this); } } @@ -109,6 +127,17 @@ private bool isFading = false; + public bool Resting = false; + private void FixedUpdate() + { + Resting = false; + } + + private void OnCollisionStay(Collision collision) + { + Resting = collision.contacts.Length > 0 && Mathf.Abs(collision.contacts[0].normal.y) > 0.7f; + } + // Update is called once per frame void Update () { if (!body.isKinematic && body.velocity.sqrMagnitude > 0.01f) @@ -145,16 +174,11 @@ } else { - deadLife -= Time.deltaTime; + deadLife -= Time.deltaTime * (leafHandler.NumLeaves >= leafHandler.MaxLeaves ? 3 : 1); if (deadLife <= 0 && !isFading) { isFading = true; SimpleTween tweenOut = new SimpleTween(); - HashSet mats = new HashSet(); - foreach (MeshRenderer mr in GetComponentsInChildren()) - { - mats.Add(mr.material); - } tweenOut.Init(v => { foreach (Material m in mats) diff --git a/FallUnity/Assets/Leaves/Pile.cs b/FallUnity/Assets/Leaves/Pile.cs new file mode 100644 index 0000000..47b81a1 --- /dev/null +++ b/FallUnity/Assets/Leaves/Pile.cs @@ -0,0 +1,16 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Pile : MonoBehaviour { + public int NumLeaves = 0; + // Use this for initialization + void Start () { + + } + + // Update is called once per frame + void Update () { + + } +} diff --git a/FallUnity/Assets/Leaves/Pile.cs.meta b/FallUnity/Assets/Leaves/Pile.cs.meta new file mode 100644 index 0000000..46f4782 --- /dev/null +++ b/FallUnity/Assets/Leaves/Pile.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 9aba3a790a516f143a6189a050883fe6 +timeCreated: 1572217739 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/FallUnity/Assets/Leaves/Pile.prefab b/FallUnity/Assets/Leaves/Pile.prefab index c9e6823..7399566 100644 --- a/FallUnity/Assets/Leaves/Pile.prefab +++ b/FallUnity/Assets/Leaves/Pile.prefab @@ -46,7 +46,7 @@ m_IsActive: 1 --- !u!1 &1455629288405468 GameObject: - m_ObjectHideFlags: 0 + m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} serializedVersion: 5 @@ -60,13 +60,28 @@ m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!1 &1865097145533800 +--- !u!1 &1676669835933754 GameObject: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} serializedVersion: 5 m_Component: + - component: {fileID: 4516590634453678} + m_Layer: 0 + m_Name: PileHolder + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!1 &1865097145533800 +GameObject: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 5 + m_Component: - component: {fileID: 4637029664340020} m_Layer: 0 m_Name: Mesh @@ -81,12 +96,11 @@ m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1430576817403556} - m_LocalRotation: {x: 0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -0.6, y: -1.1, z: 4.45} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: -1.13, y: 6.12, z: 8.16} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - - {fileID: 4637029664340020} - - {fileID: 4794401915724672} + - {fileID: 4516590634453678} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -103,18 +117,33 @@ m_Father: {fileID: 4637029664340020} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!4 &4516590634453678 +Transform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1676669835933754} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 4637029664340020} + - {fileID: 4794401915724672} + m_Father: {fileID: 4028432306176728} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!4 &4637029664340020 Transform: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1865097145533800} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0.5187102, y: 0.51870996, z: 0.51870996} m_Children: - {fileID: 4097242592220890} - m_Father: {fileID: 4028432306176728} + m_Father: {fileID: 4516590634453678} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!4 &4794401915724672 @@ -123,11 +152,11 @@ m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1455629288405468} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0.5187102, y: 0.51870996, z: 0.51870996} m_Children: [] - m_Father: {fileID: 4028432306176728} + m_Father: {fileID: 4516590634453678} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!23 &23658430294834434 diff --git a/FallUnity/Assets/Player/Player.prefab b/FallUnity/Assets/Player/Player.prefab index c9796b0..c6f5428 100644 --- a/FallUnity/Assets/Player/Player.prefab +++ b/FallUnity/Assets/Player/Player.prefab @@ -236,7 +236,9 @@ RakeBackTime: 0.15 RakeReachDist: 0.7 RakeReachRadius: 0.8 - RakeFlyForce: 100 + RakeFlyForce: 2.02 + PilePrefab: {fileID: 1430576817403556, guid: d6cf61ddfecafa14991e99ec6f1e33f0, type: 2} + PileSearchRadius: 0.7 --- !u!114 &114917061756029764 MonoBehaviour: m_ObjectHideFlags: 1 diff --git a/FallUnity/Assets/Player/PlayerController.cs b/FallUnity/Assets/Player/PlayerController.cs index a463e36..e5dd76c 100755 --- a/FallUnity/Assets/Player/PlayerController.cs +++ b/FallUnity/Assets/Player/PlayerController.cs @@ -12,11 +12,14 @@ public enum State { Walking, - Raking + Raking, + MakingPile } private State state = State.Walking; + private int leafLayer = 0; + private CharacterController charC; private AnimationHandler anim; // Use this for initialization @@ -27,6 +30,8 @@ rakeBackTween = new SimpleTween(); oldPos = transform.position; + leafLayer = LayerMask.GetMask("leaf"); + } private float velY = 0; @@ -51,6 +56,10 @@ private Vector3 oldPos = new Vector3(); + private Vector3 playerDir = new Vector3(); + + public int[] LeafsForPile; + // Update is called once per frame void Update () { @@ -60,12 +69,17 @@ { if (charC.isGrounded && state == State.Walking) { + dir.x = input.Axis(InputSource.InputAxis.MoveX); - dir.z = input.Axis(InputSource.InputAxis.MoveY); + dir.z = input.Axis(InputSource.InputAxis.MoveY); if (dir.magnitude > 0.3f) { dir.Normalize(); + + playerDir.x = dir.x; + playerDir.y = dir.y; + float speed = Speed; if (runCycle < RunFrameTime) { @@ -119,9 +133,8 @@ Vector3 moved = transform.position - oldPos; if (moved.magnitude > 0.7f * Time.deltaTime) - { - int layer = LayerMask.GetMask("leaf"); - foreach (Collider c in Physics.OverlapSphere(transform.position, PushRadius, layer)) + { + foreach (Collider c in Physics.OverlapSphere(transform.position, PushRadius, leafLayer)) { LeafPhysics leaf = c.GetComponentInParent(); if (leaf != null) @@ -136,8 +149,8 @@ } } - rakeDir = new Vector3(input.Axis(InputSource.InputAxis.RakeX), 0, input.Axis(InputSource.InputAxis.RakeY)); - if (rakeDir.magnitude < 0.2f) + Vector3 localRakeDir = new Vector3(input.Axis(InputSource.InputAxis.RakeX), 0, input.Axis(InputSource.InputAxis.RakeY)); + if (localRakeDir.magnitude < 0.2f) { rakeTime = 0; } @@ -149,8 +162,9 @@ } } - if (rakeTime >= 0 && rakeDir.magnitude > 0.7f && rakeTime < TimeToPushRake) + if (rakeTime >= 0 && localRakeDir.magnitude > 0.7f && rakeTime < TimeToPushRake) { + rakeDir = localRakeDir; state = State.Raking; float angle = Mathf.Atan2(-rakeDir.z, -rakeDir.x); @@ -170,6 +184,29 @@ rakeTimer.Start(0.15f, Rake); } + + if (state == State.Walking && input.ButtonPressedThisFrame(InputSource.InputButton.MakePile)) + { + rakeDir = playerDir; + state = State.MakingPile; + + float angle = Mathf.Atan2(-rakeDir.z, -rakeDir.x); + + if (angle < 0) angle += Mathf.PI * 2; + + AnimationHandler.Direction rakeAnimDir = AnimationHandler.Direction.UpRight; + + if (angle < Mathf.PI / 2.0f) rakeAnimDir = AnimationHandler.Direction.UpRight; + if (angle < Mathf.PI && angle >= Mathf.PI / 2.0f) rakeAnimDir = AnimationHandler.Direction.UpLeft; + if (angle < Mathf.PI * 3.0f / 2.0f && angle >= Mathf.PI) rakeAnimDir = AnimationHandler.Direction.DownLeft; + if (angle >= Mathf.PI * 3.0f / 2.0f) rakeAnimDir = AnimationHandler.Direction.DownRight; + + rakeTime = -1; + + anim.SetState("Rake", rakeAnimDir, 0); + + rakeTimer.Start(0.35f, MakePile); + } } oldPos = transform.position; @@ -200,8 +237,6 @@ rakeBackTween.Init(UpdateRakeBack, SimpleTween.QuadEaseInOut, 0, 1, RakeBackTime); rakeBackTween.OnFinish = FinishedRake; - rakeTimer.Start(RakeBackTime * 1.5f, CheckPile); - List leafs = new List(); int layer = LayerMask.GetMask("leaf"); @@ -216,14 +251,14 @@ foreach (LeafPhysics leaf in leafs) { - float rand = UnityEngine.Random.Range(0, 1); + float rand = UnityEngine.Random.Range(0, 1.0f); Vector3 startPos = leaf.transform.position; Vector3 toLeaf = startPos - transform.position; float dist = Vector3.Dot(toLeaf, -rakeDir); dist += UnityEngine.Random.Range(-0.1f, 0.1f); Vector3 pull = rakeDir * dist; - if (rand < 0.6f) + if (rand < 0.5f) { // pull the leaf back, and then destroy @@ -238,40 +273,59 @@ SimpleTween tween = new SimpleTween(v => { - leaf.transform.position = startPos + pull * v; + if (leaf != null) + { + leaf.transform.position = startPos + pull * v; + } }, SimpleTween.TweenType.EaseLinear, 0, 1, pullTime); tween.OnFinish = () => { - leaf.Body.isKinematic = false; + if (leaf != null) + { + leaf.Body.isKinematic = false; + } //GameObject.Destroy(leaf.gameObject); }; } - else if (rand < 0.8f) + else if (rand < 0.7f) { pull.Normalize(); - pull = Quaternion.Euler(UnityEngine.Random.Range(-30, 30), UnityEngine.Random.Range(-30, 30), UnityEngine.Random.Range(-30, 30)) * pull; + pull = Quaternion.Euler(UnityEngine.Random.Range(-30.0f, 30.0f), UnityEngine.Random.Range(-30.0f, 30.0f), UnityEngine.Random.Range(-30.0f, 30.0f)) * pull; pull.y += 0.3f; leaf.Body.AddForce(pull * RakeFlyForce, ForceMode.Impulse); } else { - } } } public GameObject PilePrefab; - private void CheckPile() + public float PileSearchRadius = 0.7f; + + private List potentialPile = new List(); + private void MakePile() { - + anim.SetState("Stand", anim.Dir, 0); + potentialPile.Clear(); + foreach (Collider c in Physics.OverlapSphere(transform.position + rakeDir * RakeReachDist, PileSearchRadius, leafLayer)) + { + LeafPhysics leaf = c.GetComponentInParent(); + if (leaf != null) + { + potentialPile.Add(leaf); + } + } + + } private void FinishedRake() { state = State.Walking; - anim.SetState("Stand", anim.Dir, anim.Frame); + anim.SetState("Stand", anim.Dir, 0); } private void UpdateRakeBack(float val) diff --git a/Build/fall_Data/Managed/Assembly-CSharp.dll b/Build/fall_Data/Managed/Assembly-CSharp.dll index 473b708..7e14020 100644 --- a/Build/fall_Data/Managed/Assembly-CSharp.dll +++ b/Build/fall_Data/Managed/Assembly-CSharp.dll Binary files differ diff --git a/Build/fall_Data/globalgamemanagers b/Build/fall_Data/globalgamemanagers index 4e34461..e79341a 100644 --- a/Build/fall_Data/globalgamemanagers +++ b/Build/fall_Data/globalgamemanagers Binary files differ diff --git a/Build/fall_Data/globalgamemanagers.assets b/Build/fall_Data/globalgamemanagers.assets index f90a19e..8cb05c1 100644 --- a/Build/fall_Data/globalgamemanagers.assets +++ b/Build/fall_Data/globalgamemanagers.assets Binary files differ diff --git a/Build/fall_Data/level0 b/Build/fall_Data/level0 index f49aed1..4a45106 100644 --- a/Build/fall_Data/level0 +++ b/Build/fall_Data/level0 Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets b/Build/fall_Data/sharedassets0.assets index da4c84e..3e933fc 100644 --- a/Build/fall_Data/sharedassets0.assets +++ b/Build/fall_Data/sharedassets0.assets Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets.resS b/Build/fall_Data/sharedassets0.assets.resS index 811ed41..091e899 100644 --- a/Build/fall_Data/sharedassets0.assets.resS +++ b/Build/fall_Data/sharedassets0.assets.resS Binary files differ diff --git a/FallUnity/Assets/Game/LeafSpawner.cs b/FallUnity/Assets/Game/LeafSpawner.cs index dd7cba9..beeff78 100644 --- a/FallUnity/Assets/Game/LeafSpawner.cs +++ b/FallUnity/Assets/Game/LeafSpawner.cs @@ -22,11 +22,13 @@ time += Time.deltaTime; while (time > interval) { + time -= interval; if (leafHandler != null && leafHandler.NumLeaves < leafHandler.MaxLeaves) - { - time -= interval; - Vector2 offset = Random.insideUnitCircle; - Vector3 point = transform.position + new Vector3(offset.x * Radius, 0, offset.y * Radius); + { + float angle = UnityEngine.Random.Range(0, Mathf.PI * 2); + float r = UnityEngine.Random.Range(0, Radius); + + Vector3 point = transform.position + new Vector3(Mathf.Sin(angle) * r, 0, Mathf.Cos(angle) * r); LeafPhysics leaf = GameObject.Instantiate(Leafs[Random.Range(0, Leafs.Length)]); leaves.Add(leaf); leaf.transform.position = point; diff --git a/FallUnity/Assets/Leaves/LeafHandler.cs b/FallUnity/Assets/Leaves/LeafHandler.cs index f931ce3..8ba3c89 100644 --- a/FallUnity/Assets/Leaves/LeafHandler.cs +++ b/FallUnity/Assets/Leaves/LeafHandler.cs @@ -1,28 +1,183 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class LeafHandler : MonoBehaviour { - private int numLeaves = 0; - public int NumLeaves { get { return numLeaves; } } - public int MaxLeaves = 700; - - public void AddLeaf() +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class LeafHandler : MonoBehaviour { + public int NumLeaves = 0; + public int MaxLeaves = 700; + + private HashSet leafs = new HashSet(); + + public void AddLeaf(LeafPhysics l) { - numLeaves++; - } - - public void RemoveLeaf() - { - numLeaves--; + leafs.Add(l); + NumLeaves = leafs.Count; } + + public void RemoveLeaf(LeafPhysics l) + { + leafs.Remove(l); + NumLeaves = leafs.Count; + } + + private SimpleTimer timer; + private SimpleTween tween; // Use this for initialization - void Start () { - - } - - // Update is called once per frame - void Update () { - - } -} + void Start () { + timer = new SimpleTimer(); + tween = new SimpleTween(); + //WaitForNextEvent(); + PickNextEvent(); + } + + private void WaitForNextEvent() + { + timer.Start(UnityEngine.Random.Range(7.0f, 20.0f), PickNextEvent); + } + + private Vector3 windForce = new Vector3(); + private Vector2 whirlwindCenter = new Vector3(); + private float whirlwindRadius = 0; + private float whirlwindForce = 0; + private float whirlwindForceUp = 0; + + private void PickNextEvent() + { + int eventType = UnityEngine.Random.Range(0, 2); + switch (eventType) + { + case 0: + { + // wind + float windAngle = UnityEngine.Random.Range(0, Mathf.PI * 2); + Vector3 windVector = new Vector3(Mathf.Sin(windAngle), 0, Mathf.Cos(windAngle)); + windVector.y = UnityEngine.Random.Range(0.8f, 1.2f); + float windStrength = UnityEngine.Random.Range(0.8f, 1.3f); + float fadeTime = UnityEngine.Random.Range(1.0f, 3.0f); + float windTime = UnityEngine.Random.Range(3.0f, 5.0f); + + Debug.LogError("WIND: V:" + windVector + " S:" + windStrength + " F:" + fadeTime + " T:" + windTime); + + tween.Init(v => + { + windForce = windVector * windStrength * v; + }, SimpleTween.EaseLinear, 0, 1, fadeTime); + tween.OnFinish = () => + { + tween.Init(v => + { + //windForce = windVector * windStrength * (Mathf.Sin(v * 25) + 1) * 0.2f; + }, SimpleTween.EaseLinear, 0, windTime, windTime); + tween.OnFinish = () => + { + tween.Init(v => + { + windForce = windVector * windStrength * v; + }, SimpleTween.EaseLinear, 1, 0, fadeTime); + tween.OnFinish = () => + { + WaitForNextEvent(); + }; + }; + + }; + break; + } + case 1: + { + // whirlwind + whirlwindCenter = UnityEngine.Random.insideUnitCircle * UnityEngine.Random.Range(0, 6.0f); + whirlwindRadius = UnityEngine.Random.Range(3.0f, 4.0f); + float maxWhirlwindForce = UnityEngine.Random.Range(1.0f, 1.6f); + float maxWhirlwindForceUp = UnityEngine.Random.Range(0.3f, 0.8f); + + float fadeTime = UnityEngine.Random.Range(2.0f, 4.0f); + float windTime = UnityEngine.Random.Range(6.0f, 8.0f); + + Debug.LogError("WHIRLWIND: C:" + whirlwindCenter + " R:" + whirlwindRadius + " F:" + maxWhirlwindForce + " U:" + maxWhirlwindForceUp + " F:" + fadeTime + " T:" + windTime); + + tween.Init(v => + { + whirlwindForce = maxWhirlwindForce * v; + whirlwindForceUp = maxWhirlwindForceUp * v; + }, SimpleTween.EaseLinear, 0, 1, fadeTime); + tween.OnFinish = () => + { + tween.Init(v => + { + //windForce = windVector * windStrength * (Mathf.Sin(v * 25) + 1) * 0.2f; + }, SimpleTween.EaseLinear, 0, windTime, windTime); + tween.OnFinish = () => + { + tween.Init(v => + { + whirlwindForce = maxWhirlwindForce * v; + whirlwindForceUp = maxWhirlwindForceUp * v; + }, SimpleTween.EaseLinear, 1, 0, fadeTime); + tween.OnFinish = () => + { + WaitForNextEvent(); + }; + }; + + }; + + break; + } + } + } + + // Update is called once per frame + void Update () { + bool hasWind = windForce.sqrMagnitude > 0.00001f; + bool hasWhirlwind = whirlwindForce > 0; + Vector2 windDir = new Vector2(windForce.x, windForce.y); + windDir.Normalize(); + + float distAway = 9.0f; + + + foreach (LeafPhysics leaf in leafs) + { + if (hasWind && (UnityEngine.Random.Range(0, 1f) < 0.25f || !leaf.Resting)) + { + float amount = Vector2.Dot(new Vector2(leaf.Body.velocity.x, leaf.Body.velocity.z), windDir); + amount = Math.Max(0, Math.Min(1, 8 - amount)); + leaf.Body.AddForce(new Vector3(windForce.x * UnityEngine.Random.Range(0.75f, 1.0f), + windForce.y * UnityEngine.Random.Range(0.9f, 1.0f), + windForce.z * UnityEngine.Random.Range(0.75f, 1.0f)) * Time.deltaTime * 60 * (leaf.Resting ? 3.0f : 0.4f)); + } + Vector2 d = new Vector2(leaf.transform.position.x, leaf.transform.position.z); + + if (hasWhirlwind && (UnityEngine.Random.Range(0, 1f) < 0.15f || !leaf.Resting)) + { + Vector2 offset = new Vector2(leaf.transform.position.x, leaf.transform.position.z) - whirlwindCenter; + Vector2 offsetN = offset.normalized; + float distFrom = offset.magnitude; + + if (distFrom < whirlwindRadius) + { + + Vector2 tangent = new Vector2(-offsetN.y, offsetN.x); + Vector2 force = tangent * (whirlwindRadius - distFrom) * whirlwindForce + offset * -0.9f; + + Vector3 force3D = new Vector3(force.x, whirlwindForceUp * (whirlwindRadius - distFrom + 2), force.y); + + leaf.Body.AddForce(new Vector3(force3D.x * UnityEngine.Random.Range(0.75f, 1.0f), + force3D.y * UnityEngine.Random.Range(0.9f, 1.0f), + force3D.z * UnityEngine.Random.Range(0.75f, 1.0f)) * Time.deltaTime * 60 * (leaf.Resting ? 3.0f : 0.4f)); + + } + + + } + + if (d.magnitude > distAway && !leaf.Resting) + { + //leaf.Body.apply + } + } + + } +} diff --git a/FallUnity/Assets/Leaves/LeafPhysics.cs b/FallUnity/Assets/Leaves/LeafPhysics.cs index 3355523..d59bfba 100755 --- a/FallUnity/Assets/Leaves/LeafPhysics.cs +++ b/FallUnity/Assets/Leaves/LeafPhysics.cs @@ -9,6 +9,10 @@ public Rigidbody Body { get { return body; } } private LeafHandler leafHandler; + + private List mats = new List(); + public IEnumerable Mats { get { return mats; } } + // Use this for initialization void Start () { body = GetComponentInChildren(); @@ -23,18 +27,32 @@ leafHandler = GameObject.FindObjectOfType(); if (leafHandler != null) { - leafHandler.AddLeaf(); + leafHandler.AddLeaf(this); } - deadLifeSpan = UnityEngine.Random.Range(20, 40); + deadLifeSpan = UnityEngine.Random.Range(20, 40.0f); deadLife = deadLifeSpan; + + foreach (MeshRenderer mr in GetComponentsInChildren()) + { + mats.Add(mr.material); + } + + Color c = Color.white; + c.r = UnityEngine.Random.Range(0.6f, 1.0f); + c.g = UnityEngine.Random.Range(0.6f, 1.0f); + c.b = UnityEngine.Random.Range(0.6f, 1.0f); + foreach (Material m in mats) + { + m.color = c; + } } void OnDestroy() { if (leafHandler != null) { - leafHandler.RemoveLeaf(); + leafHandler.RemoveLeaf(this); } } @@ -109,6 +127,17 @@ private bool isFading = false; + public bool Resting = false; + private void FixedUpdate() + { + Resting = false; + } + + private void OnCollisionStay(Collision collision) + { + Resting = collision.contacts.Length > 0 && Mathf.Abs(collision.contacts[0].normal.y) > 0.7f; + } + // Update is called once per frame void Update () { if (!body.isKinematic && body.velocity.sqrMagnitude > 0.01f) @@ -145,16 +174,11 @@ } else { - deadLife -= Time.deltaTime; + deadLife -= Time.deltaTime * (leafHandler.NumLeaves >= leafHandler.MaxLeaves ? 3 : 1); if (deadLife <= 0 && !isFading) { isFading = true; SimpleTween tweenOut = new SimpleTween(); - HashSet mats = new HashSet(); - foreach (MeshRenderer mr in GetComponentsInChildren()) - { - mats.Add(mr.material); - } tweenOut.Init(v => { foreach (Material m in mats) diff --git a/FallUnity/Assets/Leaves/Pile.cs b/FallUnity/Assets/Leaves/Pile.cs new file mode 100644 index 0000000..47b81a1 --- /dev/null +++ b/FallUnity/Assets/Leaves/Pile.cs @@ -0,0 +1,16 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Pile : MonoBehaviour { + public int NumLeaves = 0; + // Use this for initialization + void Start () { + + } + + // Update is called once per frame + void Update () { + + } +} diff --git a/FallUnity/Assets/Leaves/Pile.cs.meta b/FallUnity/Assets/Leaves/Pile.cs.meta new file mode 100644 index 0000000..46f4782 --- /dev/null +++ b/FallUnity/Assets/Leaves/Pile.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 9aba3a790a516f143a6189a050883fe6 +timeCreated: 1572217739 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/FallUnity/Assets/Leaves/Pile.prefab b/FallUnity/Assets/Leaves/Pile.prefab index c9e6823..7399566 100644 --- a/FallUnity/Assets/Leaves/Pile.prefab +++ b/FallUnity/Assets/Leaves/Pile.prefab @@ -46,7 +46,7 @@ m_IsActive: 1 --- !u!1 &1455629288405468 GameObject: - m_ObjectHideFlags: 0 + m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} serializedVersion: 5 @@ -60,13 +60,28 @@ m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!1 &1865097145533800 +--- !u!1 &1676669835933754 GameObject: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} serializedVersion: 5 m_Component: + - component: {fileID: 4516590634453678} + m_Layer: 0 + m_Name: PileHolder + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!1 &1865097145533800 +GameObject: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 5 + m_Component: - component: {fileID: 4637029664340020} m_Layer: 0 m_Name: Mesh @@ -81,12 +96,11 @@ m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1430576817403556} - m_LocalRotation: {x: 0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -0.6, y: -1.1, z: 4.45} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: -1.13, y: 6.12, z: 8.16} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - - {fileID: 4637029664340020} - - {fileID: 4794401915724672} + - {fileID: 4516590634453678} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -103,18 +117,33 @@ m_Father: {fileID: 4637029664340020} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!4 &4516590634453678 +Transform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1676669835933754} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 4637029664340020} + - {fileID: 4794401915724672} + m_Father: {fileID: 4028432306176728} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!4 &4637029664340020 Transform: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1865097145533800} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0.5187102, y: 0.51870996, z: 0.51870996} m_Children: - {fileID: 4097242592220890} - m_Father: {fileID: 4028432306176728} + m_Father: {fileID: 4516590634453678} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!4 &4794401915724672 @@ -123,11 +152,11 @@ m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1455629288405468} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0.5187102, y: 0.51870996, z: 0.51870996} m_Children: [] - m_Father: {fileID: 4028432306176728} + m_Father: {fileID: 4516590634453678} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!23 &23658430294834434 diff --git a/FallUnity/Assets/Player/Player.prefab b/FallUnity/Assets/Player/Player.prefab index c9796b0..c6f5428 100644 --- a/FallUnity/Assets/Player/Player.prefab +++ b/FallUnity/Assets/Player/Player.prefab @@ -236,7 +236,9 @@ RakeBackTime: 0.15 RakeReachDist: 0.7 RakeReachRadius: 0.8 - RakeFlyForce: 100 + RakeFlyForce: 2.02 + PilePrefab: {fileID: 1430576817403556, guid: d6cf61ddfecafa14991e99ec6f1e33f0, type: 2} + PileSearchRadius: 0.7 --- !u!114 &114917061756029764 MonoBehaviour: m_ObjectHideFlags: 1 diff --git a/FallUnity/Assets/Player/PlayerController.cs b/FallUnity/Assets/Player/PlayerController.cs index a463e36..e5dd76c 100755 --- a/FallUnity/Assets/Player/PlayerController.cs +++ b/FallUnity/Assets/Player/PlayerController.cs @@ -12,11 +12,14 @@ public enum State { Walking, - Raking + Raking, + MakingPile } private State state = State.Walking; + private int leafLayer = 0; + private CharacterController charC; private AnimationHandler anim; // Use this for initialization @@ -27,6 +30,8 @@ rakeBackTween = new SimpleTween(); oldPos = transform.position; + leafLayer = LayerMask.GetMask("leaf"); + } private float velY = 0; @@ -51,6 +56,10 @@ private Vector3 oldPos = new Vector3(); + private Vector3 playerDir = new Vector3(); + + public int[] LeafsForPile; + // Update is called once per frame void Update () { @@ -60,12 +69,17 @@ { if (charC.isGrounded && state == State.Walking) { + dir.x = input.Axis(InputSource.InputAxis.MoveX); - dir.z = input.Axis(InputSource.InputAxis.MoveY); + dir.z = input.Axis(InputSource.InputAxis.MoveY); if (dir.magnitude > 0.3f) { dir.Normalize(); + + playerDir.x = dir.x; + playerDir.y = dir.y; + float speed = Speed; if (runCycle < RunFrameTime) { @@ -119,9 +133,8 @@ Vector3 moved = transform.position - oldPos; if (moved.magnitude > 0.7f * Time.deltaTime) - { - int layer = LayerMask.GetMask("leaf"); - foreach (Collider c in Physics.OverlapSphere(transform.position, PushRadius, layer)) + { + foreach (Collider c in Physics.OverlapSphere(transform.position, PushRadius, leafLayer)) { LeafPhysics leaf = c.GetComponentInParent(); if (leaf != null) @@ -136,8 +149,8 @@ } } - rakeDir = new Vector3(input.Axis(InputSource.InputAxis.RakeX), 0, input.Axis(InputSource.InputAxis.RakeY)); - if (rakeDir.magnitude < 0.2f) + Vector3 localRakeDir = new Vector3(input.Axis(InputSource.InputAxis.RakeX), 0, input.Axis(InputSource.InputAxis.RakeY)); + if (localRakeDir.magnitude < 0.2f) { rakeTime = 0; } @@ -149,8 +162,9 @@ } } - if (rakeTime >= 0 && rakeDir.magnitude > 0.7f && rakeTime < TimeToPushRake) + if (rakeTime >= 0 && localRakeDir.magnitude > 0.7f && rakeTime < TimeToPushRake) { + rakeDir = localRakeDir; state = State.Raking; float angle = Mathf.Atan2(-rakeDir.z, -rakeDir.x); @@ -170,6 +184,29 @@ rakeTimer.Start(0.15f, Rake); } + + if (state == State.Walking && input.ButtonPressedThisFrame(InputSource.InputButton.MakePile)) + { + rakeDir = playerDir; + state = State.MakingPile; + + float angle = Mathf.Atan2(-rakeDir.z, -rakeDir.x); + + if (angle < 0) angle += Mathf.PI * 2; + + AnimationHandler.Direction rakeAnimDir = AnimationHandler.Direction.UpRight; + + if (angle < Mathf.PI / 2.0f) rakeAnimDir = AnimationHandler.Direction.UpRight; + if (angle < Mathf.PI && angle >= Mathf.PI / 2.0f) rakeAnimDir = AnimationHandler.Direction.UpLeft; + if (angle < Mathf.PI * 3.0f / 2.0f && angle >= Mathf.PI) rakeAnimDir = AnimationHandler.Direction.DownLeft; + if (angle >= Mathf.PI * 3.0f / 2.0f) rakeAnimDir = AnimationHandler.Direction.DownRight; + + rakeTime = -1; + + anim.SetState("Rake", rakeAnimDir, 0); + + rakeTimer.Start(0.35f, MakePile); + } } oldPos = transform.position; @@ -200,8 +237,6 @@ rakeBackTween.Init(UpdateRakeBack, SimpleTween.QuadEaseInOut, 0, 1, RakeBackTime); rakeBackTween.OnFinish = FinishedRake; - rakeTimer.Start(RakeBackTime * 1.5f, CheckPile); - List leafs = new List(); int layer = LayerMask.GetMask("leaf"); @@ -216,14 +251,14 @@ foreach (LeafPhysics leaf in leafs) { - float rand = UnityEngine.Random.Range(0, 1); + float rand = UnityEngine.Random.Range(0, 1.0f); Vector3 startPos = leaf.transform.position; Vector3 toLeaf = startPos - transform.position; float dist = Vector3.Dot(toLeaf, -rakeDir); dist += UnityEngine.Random.Range(-0.1f, 0.1f); Vector3 pull = rakeDir * dist; - if (rand < 0.6f) + if (rand < 0.5f) { // pull the leaf back, and then destroy @@ -238,40 +273,59 @@ SimpleTween tween = new SimpleTween(v => { - leaf.transform.position = startPos + pull * v; + if (leaf != null) + { + leaf.transform.position = startPos + pull * v; + } }, SimpleTween.TweenType.EaseLinear, 0, 1, pullTime); tween.OnFinish = () => { - leaf.Body.isKinematic = false; + if (leaf != null) + { + leaf.Body.isKinematic = false; + } //GameObject.Destroy(leaf.gameObject); }; } - else if (rand < 0.8f) + else if (rand < 0.7f) { pull.Normalize(); - pull = Quaternion.Euler(UnityEngine.Random.Range(-30, 30), UnityEngine.Random.Range(-30, 30), UnityEngine.Random.Range(-30, 30)) * pull; + pull = Quaternion.Euler(UnityEngine.Random.Range(-30.0f, 30.0f), UnityEngine.Random.Range(-30.0f, 30.0f), UnityEngine.Random.Range(-30.0f, 30.0f)) * pull; pull.y += 0.3f; leaf.Body.AddForce(pull * RakeFlyForce, ForceMode.Impulse); } else { - } } } public GameObject PilePrefab; - private void CheckPile() + public float PileSearchRadius = 0.7f; + + private List potentialPile = new List(); + private void MakePile() { - + anim.SetState("Stand", anim.Dir, 0); + potentialPile.Clear(); + foreach (Collider c in Physics.OverlapSphere(transform.position + rakeDir * RakeReachDist, PileSearchRadius, leafLayer)) + { + LeafPhysics leaf = c.GetComponentInParent(); + if (leaf != null) + { + potentialPile.Add(leaf); + } + } + + } private void FinishedRake() { state = State.Walking; - anim.SetState("Stand", anim.Dir, anim.Frame); + anim.SetState("Stand", anim.Dir, 0); } private void UpdateRakeBack(float val) diff --git a/FallUnity/Assets/PlayerInput/InputSource.cs b/FallUnity/Assets/PlayerInput/InputSource.cs index 2cccceb..8cf23ec 100644 --- a/FallUnity/Assets/PlayerInput/InputSource.cs +++ b/FallUnity/Assets/PlayerInput/InputSource.cs @@ -12,6 +12,9 @@ { MenuSelect, MenuCancel, + + MakePile, + DestroyPile } public enum InputAxis diff --git a/Build/fall_Data/Managed/Assembly-CSharp.dll b/Build/fall_Data/Managed/Assembly-CSharp.dll index 473b708..7e14020 100644 --- a/Build/fall_Data/Managed/Assembly-CSharp.dll +++ b/Build/fall_Data/Managed/Assembly-CSharp.dll Binary files differ diff --git a/Build/fall_Data/globalgamemanagers b/Build/fall_Data/globalgamemanagers index 4e34461..e79341a 100644 --- a/Build/fall_Data/globalgamemanagers +++ b/Build/fall_Data/globalgamemanagers Binary files differ diff --git a/Build/fall_Data/globalgamemanagers.assets b/Build/fall_Data/globalgamemanagers.assets index f90a19e..8cb05c1 100644 --- a/Build/fall_Data/globalgamemanagers.assets +++ b/Build/fall_Data/globalgamemanagers.assets Binary files differ diff --git a/Build/fall_Data/level0 b/Build/fall_Data/level0 index f49aed1..4a45106 100644 --- a/Build/fall_Data/level0 +++ b/Build/fall_Data/level0 Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets b/Build/fall_Data/sharedassets0.assets index da4c84e..3e933fc 100644 --- a/Build/fall_Data/sharedassets0.assets +++ b/Build/fall_Data/sharedassets0.assets Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets.resS b/Build/fall_Data/sharedassets0.assets.resS index 811ed41..091e899 100644 --- a/Build/fall_Data/sharedassets0.assets.resS +++ b/Build/fall_Data/sharedassets0.assets.resS Binary files differ diff --git a/FallUnity/Assets/Game/LeafSpawner.cs b/FallUnity/Assets/Game/LeafSpawner.cs index dd7cba9..beeff78 100644 --- a/FallUnity/Assets/Game/LeafSpawner.cs +++ b/FallUnity/Assets/Game/LeafSpawner.cs @@ -22,11 +22,13 @@ time += Time.deltaTime; while (time > interval) { + time -= interval; if (leafHandler != null && leafHandler.NumLeaves < leafHandler.MaxLeaves) - { - time -= interval; - Vector2 offset = Random.insideUnitCircle; - Vector3 point = transform.position + new Vector3(offset.x * Radius, 0, offset.y * Radius); + { + float angle = UnityEngine.Random.Range(0, Mathf.PI * 2); + float r = UnityEngine.Random.Range(0, Radius); + + Vector3 point = transform.position + new Vector3(Mathf.Sin(angle) * r, 0, Mathf.Cos(angle) * r); LeafPhysics leaf = GameObject.Instantiate(Leafs[Random.Range(0, Leafs.Length)]); leaves.Add(leaf); leaf.transform.position = point; diff --git a/FallUnity/Assets/Leaves/LeafHandler.cs b/FallUnity/Assets/Leaves/LeafHandler.cs index f931ce3..8ba3c89 100644 --- a/FallUnity/Assets/Leaves/LeafHandler.cs +++ b/FallUnity/Assets/Leaves/LeafHandler.cs @@ -1,28 +1,183 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class LeafHandler : MonoBehaviour { - private int numLeaves = 0; - public int NumLeaves { get { return numLeaves; } } - public int MaxLeaves = 700; - - public void AddLeaf() +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class LeafHandler : MonoBehaviour { + public int NumLeaves = 0; + public int MaxLeaves = 700; + + private HashSet leafs = new HashSet(); + + public void AddLeaf(LeafPhysics l) { - numLeaves++; - } - - public void RemoveLeaf() - { - numLeaves--; + leafs.Add(l); + NumLeaves = leafs.Count; } + + public void RemoveLeaf(LeafPhysics l) + { + leafs.Remove(l); + NumLeaves = leafs.Count; + } + + private SimpleTimer timer; + private SimpleTween tween; // Use this for initialization - void Start () { - - } - - // Update is called once per frame - void Update () { - - } -} + void Start () { + timer = new SimpleTimer(); + tween = new SimpleTween(); + //WaitForNextEvent(); + PickNextEvent(); + } + + private void WaitForNextEvent() + { + timer.Start(UnityEngine.Random.Range(7.0f, 20.0f), PickNextEvent); + } + + private Vector3 windForce = new Vector3(); + private Vector2 whirlwindCenter = new Vector3(); + private float whirlwindRadius = 0; + private float whirlwindForce = 0; + private float whirlwindForceUp = 0; + + private void PickNextEvent() + { + int eventType = UnityEngine.Random.Range(0, 2); + switch (eventType) + { + case 0: + { + // wind + float windAngle = UnityEngine.Random.Range(0, Mathf.PI * 2); + Vector3 windVector = new Vector3(Mathf.Sin(windAngle), 0, Mathf.Cos(windAngle)); + windVector.y = UnityEngine.Random.Range(0.8f, 1.2f); + float windStrength = UnityEngine.Random.Range(0.8f, 1.3f); + float fadeTime = UnityEngine.Random.Range(1.0f, 3.0f); + float windTime = UnityEngine.Random.Range(3.0f, 5.0f); + + Debug.LogError("WIND: V:" + windVector + " S:" + windStrength + " F:" + fadeTime + " T:" + windTime); + + tween.Init(v => + { + windForce = windVector * windStrength * v; + }, SimpleTween.EaseLinear, 0, 1, fadeTime); + tween.OnFinish = () => + { + tween.Init(v => + { + //windForce = windVector * windStrength * (Mathf.Sin(v * 25) + 1) * 0.2f; + }, SimpleTween.EaseLinear, 0, windTime, windTime); + tween.OnFinish = () => + { + tween.Init(v => + { + windForce = windVector * windStrength * v; + }, SimpleTween.EaseLinear, 1, 0, fadeTime); + tween.OnFinish = () => + { + WaitForNextEvent(); + }; + }; + + }; + break; + } + case 1: + { + // whirlwind + whirlwindCenter = UnityEngine.Random.insideUnitCircle * UnityEngine.Random.Range(0, 6.0f); + whirlwindRadius = UnityEngine.Random.Range(3.0f, 4.0f); + float maxWhirlwindForce = UnityEngine.Random.Range(1.0f, 1.6f); + float maxWhirlwindForceUp = UnityEngine.Random.Range(0.3f, 0.8f); + + float fadeTime = UnityEngine.Random.Range(2.0f, 4.0f); + float windTime = UnityEngine.Random.Range(6.0f, 8.0f); + + Debug.LogError("WHIRLWIND: C:" + whirlwindCenter + " R:" + whirlwindRadius + " F:" + maxWhirlwindForce + " U:" + maxWhirlwindForceUp + " F:" + fadeTime + " T:" + windTime); + + tween.Init(v => + { + whirlwindForce = maxWhirlwindForce * v; + whirlwindForceUp = maxWhirlwindForceUp * v; + }, SimpleTween.EaseLinear, 0, 1, fadeTime); + tween.OnFinish = () => + { + tween.Init(v => + { + //windForce = windVector * windStrength * (Mathf.Sin(v * 25) + 1) * 0.2f; + }, SimpleTween.EaseLinear, 0, windTime, windTime); + tween.OnFinish = () => + { + tween.Init(v => + { + whirlwindForce = maxWhirlwindForce * v; + whirlwindForceUp = maxWhirlwindForceUp * v; + }, SimpleTween.EaseLinear, 1, 0, fadeTime); + tween.OnFinish = () => + { + WaitForNextEvent(); + }; + }; + + }; + + break; + } + } + } + + // Update is called once per frame + void Update () { + bool hasWind = windForce.sqrMagnitude > 0.00001f; + bool hasWhirlwind = whirlwindForce > 0; + Vector2 windDir = new Vector2(windForce.x, windForce.y); + windDir.Normalize(); + + float distAway = 9.0f; + + + foreach (LeafPhysics leaf in leafs) + { + if (hasWind && (UnityEngine.Random.Range(0, 1f) < 0.25f || !leaf.Resting)) + { + float amount = Vector2.Dot(new Vector2(leaf.Body.velocity.x, leaf.Body.velocity.z), windDir); + amount = Math.Max(0, Math.Min(1, 8 - amount)); + leaf.Body.AddForce(new Vector3(windForce.x * UnityEngine.Random.Range(0.75f, 1.0f), + windForce.y * UnityEngine.Random.Range(0.9f, 1.0f), + windForce.z * UnityEngine.Random.Range(0.75f, 1.0f)) * Time.deltaTime * 60 * (leaf.Resting ? 3.0f : 0.4f)); + } + Vector2 d = new Vector2(leaf.transform.position.x, leaf.transform.position.z); + + if (hasWhirlwind && (UnityEngine.Random.Range(0, 1f) < 0.15f || !leaf.Resting)) + { + Vector2 offset = new Vector2(leaf.transform.position.x, leaf.transform.position.z) - whirlwindCenter; + Vector2 offsetN = offset.normalized; + float distFrom = offset.magnitude; + + if (distFrom < whirlwindRadius) + { + + Vector2 tangent = new Vector2(-offsetN.y, offsetN.x); + Vector2 force = tangent * (whirlwindRadius - distFrom) * whirlwindForce + offset * -0.9f; + + Vector3 force3D = new Vector3(force.x, whirlwindForceUp * (whirlwindRadius - distFrom + 2), force.y); + + leaf.Body.AddForce(new Vector3(force3D.x * UnityEngine.Random.Range(0.75f, 1.0f), + force3D.y * UnityEngine.Random.Range(0.9f, 1.0f), + force3D.z * UnityEngine.Random.Range(0.75f, 1.0f)) * Time.deltaTime * 60 * (leaf.Resting ? 3.0f : 0.4f)); + + } + + + } + + if (d.magnitude > distAway && !leaf.Resting) + { + //leaf.Body.apply + } + } + + } +} diff --git a/FallUnity/Assets/Leaves/LeafPhysics.cs b/FallUnity/Assets/Leaves/LeafPhysics.cs index 3355523..d59bfba 100755 --- a/FallUnity/Assets/Leaves/LeafPhysics.cs +++ b/FallUnity/Assets/Leaves/LeafPhysics.cs @@ -9,6 +9,10 @@ public Rigidbody Body { get { return body; } } private LeafHandler leafHandler; + + private List mats = new List(); + public IEnumerable Mats { get { return mats; } } + // Use this for initialization void Start () { body = GetComponentInChildren(); @@ -23,18 +27,32 @@ leafHandler = GameObject.FindObjectOfType(); if (leafHandler != null) { - leafHandler.AddLeaf(); + leafHandler.AddLeaf(this); } - deadLifeSpan = UnityEngine.Random.Range(20, 40); + deadLifeSpan = UnityEngine.Random.Range(20, 40.0f); deadLife = deadLifeSpan; + + foreach (MeshRenderer mr in GetComponentsInChildren()) + { + mats.Add(mr.material); + } + + Color c = Color.white; + c.r = UnityEngine.Random.Range(0.6f, 1.0f); + c.g = UnityEngine.Random.Range(0.6f, 1.0f); + c.b = UnityEngine.Random.Range(0.6f, 1.0f); + foreach (Material m in mats) + { + m.color = c; + } } void OnDestroy() { if (leafHandler != null) { - leafHandler.RemoveLeaf(); + leafHandler.RemoveLeaf(this); } } @@ -109,6 +127,17 @@ private bool isFading = false; + public bool Resting = false; + private void FixedUpdate() + { + Resting = false; + } + + private void OnCollisionStay(Collision collision) + { + Resting = collision.contacts.Length > 0 && Mathf.Abs(collision.contacts[0].normal.y) > 0.7f; + } + // Update is called once per frame void Update () { if (!body.isKinematic && body.velocity.sqrMagnitude > 0.01f) @@ -145,16 +174,11 @@ } else { - deadLife -= Time.deltaTime; + deadLife -= Time.deltaTime * (leafHandler.NumLeaves >= leafHandler.MaxLeaves ? 3 : 1); if (deadLife <= 0 && !isFading) { isFading = true; SimpleTween tweenOut = new SimpleTween(); - HashSet mats = new HashSet(); - foreach (MeshRenderer mr in GetComponentsInChildren()) - { - mats.Add(mr.material); - } tweenOut.Init(v => { foreach (Material m in mats) diff --git a/FallUnity/Assets/Leaves/Pile.cs b/FallUnity/Assets/Leaves/Pile.cs new file mode 100644 index 0000000..47b81a1 --- /dev/null +++ b/FallUnity/Assets/Leaves/Pile.cs @@ -0,0 +1,16 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Pile : MonoBehaviour { + public int NumLeaves = 0; + // Use this for initialization + void Start () { + + } + + // Update is called once per frame + void Update () { + + } +} diff --git a/FallUnity/Assets/Leaves/Pile.cs.meta b/FallUnity/Assets/Leaves/Pile.cs.meta new file mode 100644 index 0000000..46f4782 --- /dev/null +++ b/FallUnity/Assets/Leaves/Pile.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 9aba3a790a516f143a6189a050883fe6 +timeCreated: 1572217739 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/FallUnity/Assets/Leaves/Pile.prefab b/FallUnity/Assets/Leaves/Pile.prefab index c9e6823..7399566 100644 --- a/FallUnity/Assets/Leaves/Pile.prefab +++ b/FallUnity/Assets/Leaves/Pile.prefab @@ -46,7 +46,7 @@ m_IsActive: 1 --- !u!1 &1455629288405468 GameObject: - m_ObjectHideFlags: 0 + m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} serializedVersion: 5 @@ -60,13 +60,28 @@ m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!1 &1865097145533800 +--- !u!1 &1676669835933754 GameObject: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} serializedVersion: 5 m_Component: + - component: {fileID: 4516590634453678} + m_Layer: 0 + m_Name: PileHolder + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!1 &1865097145533800 +GameObject: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 5 + m_Component: - component: {fileID: 4637029664340020} m_Layer: 0 m_Name: Mesh @@ -81,12 +96,11 @@ m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1430576817403556} - m_LocalRotation: {x: 0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -0.6, y: -1.1, z: 4.45} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: -1.13, y: 6.12, z: 8.16} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - - {fileID: 4637029664340020} - - {fileID: 4794401915724672} + - {fileID: 4516590634453678} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -103,18 +117,33 @@ m_Father: {fileID: 4637029664340020} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!4 &4516590634453678 +Transform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1676669835933754} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 4637029664340020} + - {fileID: 4794401915724672} + m_Father: {fileID: 4028432306176728} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!4 &4637029664340020 Transform: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1865097145533800} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0.5187102, y: 0.51870996, z: 0.51870996} m_Children: - {fileID: 4097242592220890} - m_Father: {fileID: 4028432306176728} + m_Father: {fileID: 4516590634453678} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!4 &4794401915724672 @@ -123,11 +152,11 @@ m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1455629288405468} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0.5187102, y: 0.51870996, z: 0.51870996} m_Children: [] - m_Father: {fileID: 4028432306176728} + m_Father: {fileID: 4516590634453678} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!23 &23658430294834434 diff --git a/FallUnity/Assets/Player/Player.prefab b/FallUnity/Assets/Player/Player.prefab index c9796b0..c6f5428 100644 --- a/FallUnity/Assets/Player/Player.prefab +++ b/FallUnity/Assets/Player/Player.prefab @@ -236,7 +236,9 @@ RakeBackTime: 0.15 RakeReachDist: 0.7 RakeReachRadius: 0.8 - RakeFlyForce: 100 + RakeFlyForce: 2.02 + PilePrefab: {fileID: 1430576817403556, guid: d6cf61ddfecafa14991e99ec6f1e33f0, type: 2} + PileSearchRadius: 0.7 --- !u!114 &114917061756029764 MonoBehaviour: m_ObjectHideFlags: 1 diff --git a/FallUnity/Assets/Player/PlayerController.cs b/FallUnity/Assets/Player/PlayerController.cs index a463e36..e5dd76c 100755 --- a/FallUnity/Assets/Player/PlayerController.cs +++ b/FallUnity/Assets/Player/PlayerController.cs @@ -12,11 +12,14 @@ public enum State { Walking, - Raking + Raking, + MakingPile } private State state = State.Walking; + private int leafLayer = 0; + private CharacterController charC; private AnimationHandler anim; // Use this for initialization @@ -27,6 +30,8 @@ rakeBackTween = new SimpleTween(); oldPos = transform.position; + leafLayer = LayerMask.GetMask("leaf"); + } private float velY = 0; @@ -51,6 +56,10 @@ private Vector3 oldPos = new Vector3(); + private Vector3 playerDir = new Vector3(); + + public int[] LeafsForPile; + // Update is called once per frame void Update () { @@ -60,12 +69,17 @@ { if (charC.isGrounded && state == State.Walking) { + dir.x = input.Axis(InputSource.InputAxis.MoveX); - dir.z = input.Axis(InputSource.InputAxis.MoveY); + dir.z = input.Axis(InputSource.InputAxis.MoveY); if (dir.magnitude > 0.3f) { dir.Normalize(); + + playerDir.x = dir.x; + playerDir.y = dir.y; + float speed = Speed; if (runCycle < RunFrameTime) { @@ -119,9 +133,8 @@ Vector3 moved = transform.position - oldPos; if (moved.magnitude > 0.7f * Time.deltaTime) - { - int layer = LayerMask.GetMask("leaf"); - foreach (Collider c in Physics.OverlapSphere(transform.position, PushRadius, layer)) + { + foreach (Collider c in Physics.OverlapSphere(transform.position, PushRadius, leafLayer)) { LeafPhysics leaf = c.GetComponentInParent(); if (leaf != null) @@ -136,8 +149,8 @@ } } - rakeDir = new Vector3(input.Axis(InputSource.InputAxis.RakeX), 0, input.Axis(InputSource.InputAxis.RakeY)); - if (rakeDir.magnitude < 0.2f) + Vector3 localRakeDir = new Vector3(input.Axis(InputSource.InputAxis.RakeX), 0, input.Axis(InputSource.InputAxis.RakeY)); + if (localRakeDir.magnitude < 0.2f) { rakeTime = 0; } @@ -149,8 +162,9 @@ } } - if (rakeTime >= 0 && rakeDir.magnitude > 0.7f && rakeTime < TimeToPushRake) + if (rakeTime >= 0 && localRakeDir.magnitude > 0.7f && rakeTime < TimeToPushRake) { + rakeDir = localRakeDir; state = State.Raking; float angle = Mathf.Atan2(-rakeDir.z, -rakeDir.x); @@ -170,6 +184,29 @@ rakeTimer.Start(0.15f, Rake); } + + if (state == State.Walking && input.ButtonPressedThisFrame(InputSource.InputButton.MakePile)) + { + rakeDir = playerDir; + state = State.MakingPile; + + float angle = Mathf.Atan2(-rakeDir.z, -rakeDir.x); + + if (angle < 0) angle += Mathf.PI * 2; + + AnimationHandler.Direction rakeAnimDir = AnimationHandler.Direction.UpRight; + + if (angle < Mathf.PI / 2.0f) rakeAnimDir = AnimationHandler.Direction.UpRight; + if (angle < Mathf.PI && angle >= Mathf.PI / 2.0f) rakeAnimDir = AnimationHandler.Direction.UpLeft; + if (angle < Mathf.PI * 3.0f / 2.0f && angle >= Mathf.PI) rakeAnimDir = AnimationHandler.Direction.DownLeft; + if (angle >= Mathf.PI * 3.0f / 2.0f) rakeAnimDir = AnimationHandler.Direction.DownRight; + + rakeTime = -1; + + anim.SetState("Rake", rakeAnimDir, 0); + + rakeTimer.Start(0.35f, MakePile); + } } oldPos = transform.position; @@ -200,8 +237,6 @@ rakeBackTween.Init(UpdateRakeBack, SimpleTween.QuadEaseInOut, 0, 1, RakeBackTime); rakeBackTween.OnFinish = FinishedRake; - rakeTimer.Start(RakeBackTime * 1.5f, CheckPile); - List leafs = new List(); int layer = LayerMask.GetMask("leaf"); @@ -216,14 +251,14 @@ foreach (LeafPhysics leaf in leafs) { - float rand = UnityEngine.Random.Range(0, 1); + float rand = UnityEngine.Random.Range(0, 1.0f); Vector3 startPos = leaf.transform.position; Vector3 toLeaf = startPos - transform.position; float dist = Vector3.Dot(toLeaf, -rakeDir); dist += UnityEngine.Random.Range(-0.1f, 0.1f); Vector3 pull = rakeDir * dist; - if (rand < 0.6f) + if (rand < 0.5f) { // pull the leaf back, and then destroy @@ -238,40 +273,59 @@ SimpleTween tween = new SimpleTween(v => { - leaf.transform.position = startPos + pull * v; + if (leaf != null) + { + leaf.transform.position = startPos + pull * v; + } }, SimpleTween.TweenType.EaseLinear, 0, 1, pullTime); tween.OnFinish = () => { - leaf.Body.isKinematic = false; + if (leaf != null) + { + leaf.Body.isKinematic = false; + } //GameObject.Destroy(leaf.gameObject); }; } - else if (rand < 0.8f) + else if (rand < 0.7f) { pull.Normalize(); - pull = Quaternion.Euler(UnityEngine.Random.Range(-30, 30), UnityEngine.Random.Range(-30, 30), UnityEngine.Random.Range(-30, 30)) * pull; + pull = Quaternion.Euler(UnityEngine.Random.Range(-30.0f, 30.0f), UnityEngine.Random.Range(-30.0f, 30.0f), UnityEngine.Random.Range(-30.0f, 30.0f)) * pull; pull.y += 0.3f; leaf.Body.AddForce(pull * RakeFlyForce, ForceMode.Impulse); } else { - } } } public GameObject PilePrefab; - private void CheckPile() + public float PileSearchRadius = 0.7f; + + private List potentialPile = new List(); + private void MakePile() { - + anim.SetState("Stand", anim.Dir, 0); + potentialPile.Clear(); + foreach (Collider c in Physics.OverlapSphere(transform.position + rakeDir * RakeReachDist, PileSearchRadius, leafLayer)) + { + LeafPhysics leaf = c.GetComponentInParent(); + if (leaf != null) + { + potentialPile.Add(leaf); + } + } + + } private void FinishedRake() { state = State.Walking; - anim.SetState("Stand", anim.Dir, anim.Frame); + anim.SetState("Stand", anim.Dir, 0); } private void UpdateRakeBack(float val) diff --git a/FallUnity/Assets/PlayerInput/InputSource.cs b/FallUnity/Assets/PlayerInput/InputSource.cs index 2cccceb..8cf23ec 100644 --- a/FallUnity/Assets/PlayerInput/InputSource.cs +++ b/FallUnity/Assets/PlayerInput/InputSource.cs @@ -12,6 +12,9 @@ { MenuSelect, MenuCancel, + + MakePile, + DestroyPile } public enum InputAxis diff --git a/FallUnity/Assets/PlayerInput/KeyboardMouseInputSource.cs b/FallUnity/Assets/PlayerInput/KeyboardMouseInputSource.cs index fc97956..9ea58d2 100644 --- a/FallUnity/Assets/PlayerInput/KeyboardMouseInputSource.cs +++ b/FallUnity/Assets/PlayerInput/KeyboardMouseInputSource.cs @@ -41,7 +41,8 @@ { InputButton.MenuSelect, KeyCode.Return }, { InputButton.MenuCancel, KeyCode.Escape }, - //{ InputButton.UseItem, KeyCode.Space }, + { InputButton.MakePile, KeyCode.Space }, + { InputButton.DestroyPile, KeyCode.Backspace }, //{ InputButton.PickA, KeyCode.Q }, //{ InputButton.PickB, KeyCode.E }, diff --git a/Build/fall_Data/Managed/Assembly-CSharp.dll b/Build/fall_Data/Managed/Assembly-CSharp.dll index 473b708..7e14020 100644 --- a/Build/fall_Data/Managed/Assembly-CSharp.dll +++ b/Build/fall_Data/Managed/Assembly-CSharp.dll Binary files differ diff --git a/Build/fall_Data/globalgamemanagers b/Build/fall_Data/globalgamemanagers index 4e34461..e79341a 100644 --- a/Build/fall_Data/globalgamemanagers +++ b/Build/fall_Data/globalgamemanagers Binary files differ diff --git a/Build/fall_Data/globalgamemanagers.assets b/Build/fall_Data/globalgamemanagers.assets index f90a19e..8cb05c1 100644 --- a/Build/fall_Data/globalgamemanagers.assets +++ b/Build/fall_Data/globalgamemanagers.assets Binary files differ diff --git a/Build/fall_Data/level0 b/Build/fall_Data/level0 index f49aed1..4a45106 100644 --- a/Build/fall_Data/level0 +++ b/Build/fall_Data/level0 Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets b/Build/fall_Data/sharedassets0.assets index da4c84e..3e933fc 100644 --- a/Build/fall_Data/sharedassets0.assets +++ b/Build/fall_Data/sharedassets0.assets Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets.resS b/Build/fall_Data/sharedassets0.assets.resS index 811ed41..091e899 100644 --- a/Build/fall_Data/sharedassets0.assets.resS +++ b/Build/fall_Data/sharedassets0.assets.resS Binary files differ diff --git a/FallUnity/Assets/Game/LeafSpawner.cs b/FallUnity/Assets/Game/LeafSpawner.cs index dd7cba9..beeff78 100644 --- a/FallUnity/Assets/Game/LeafSpawner.cs +++ b/FallUnity/Assets/Game/LeafSpawner.cs @@ -22,11 +22,13 @@ time += Time.deltaTime; while (time > interval) { + time -= interval; if (leafHandler != null && leafHandler.NumLeaves < leafHandler.MaxLeaves) - { - time -= interval; - Vector2 offset = Random.insideUnitCircle; - Vector3 point = transform.position + new Vector3(offset.x * Radius, 0, offset.y * Radius); + { + float angle = UnityEngine.Random.Range(0, Mathf.PI * 2); + float r = UnityEngine.Random.Range(0, Radius); + + Vector3 point = transform.position + new Vector3(Mathf.Sin(angle) * r, 0, Mathf.Cos(angle) * r); LeafPhysics leaf = GameObject.Instantiate(Leafs[Random.Range(0, Leafs.Length)]); leaves.Add(leaf); leaf.transform.position = point; diff --git a/FallUnity/Assets/Leaves/LeafHandler.cs b/FallUnity/Assets/Leaves/LeafHandler.cs index f931ce3..8ba3c89 100644 --- a/FallUnity/Assets/Leaves/LeafHandler.cs +++ b/FallUnity/Assets/Leaves/LeafHandler.cs @@ -1,28 +1,183 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class LeafHandler : MonoBehaviour { - private int numLeaves = 0; - public int NumLeaves { get { return numLeaves; } } - public int MaxLeaves = 700; - - public void AddLeaf() +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class LeafHandler : MonoBehaviour { + public int NumLeaves = 0; + public int MaxLeaves = 700; + + private HashSet leafs = new HashSet(); + + public void AddLeaf(LeafPhysics l) { - numLeaves++; - } - - public void RemoveLeaf() - { - numLeaves--; + leafs.Add(l); + NumLeaves = leafs.Count; } + + public void RemoveLeaf(LeafPhysics l) + { + leafs.Remove(l); + NumLeaves = leafs.Count; + } + + private SimpleTimer timer; + private SimpleTween tween; // Use this for initialization - void Start () { - - } - - // Update is called once per frame - void Update () { - - } -} + void Start () { + timer = new SimpleTimer(); + tween = new SimpleTween(); + //WaitForNextEvent(); + PickNextEvent(); + } + + private void WaitForNextEvent() + { + timer.Start(UnityEngine.Random.Range(7.0f, 20.0f), PickNextEvent); + } + + private Vector3 windForce = new Vector3(); + private Vector2 whirlwindCenter = new Vector3(); + private float whirlwindRadius = 0; + private float whirlwindForce = 0; + private float whirlwindForceUp = 0; + + private void PickNextEvent() + { + int eventType = UnityEngine.Random.Range(0, 2); + switch (eventType) + { + case 0: + { + // wind + float windAngle = UnityEngine.Random.Range(0, Mathf.PI * 2); + Vector3 windVector = new Vector3(Mathf.Sin(windAngle), 0, Mathf.Cos(windAngle)); + windVector.y = UnityEngine.Random.Range(0.8f, 1.2f); + float windStrength = UnityEngine.Random.Range(0.8f, 1.3f); + float fadeTime = UnityEngine.Random.Range(1.0f, 3.0f); + float windTime = UnityEngine.Random.Range(3.0f, 5.0f); + + Debug.LogError("WIND: V:" + windVector + " S:" + windStrength + " F:" + fadeTime + " T:" + windTime); + + tween.Init(v => + { + windForce = windVector * windStrength * v; + }, SimpleTween.EaseLinear, 0, 1, fadeTime); + tween.OnFinish = () => + { + tween.Init(v => + { + //windForce = windVector * windStrength * (Mathf.Sin(v * 25) + 1) * 0.2f; + }, SimpleTween.EaseLinear, 0, windTime, windTime); + tween.OnFinish = () => + { + tween.Init(v => + { + windForce = windVector * windStrength * v; + }, SimpleTween.EaseLinear, 1, 0, fadeTime); + tween.OnFinish = () => + { + WaitForNextEvent(); + }; + }; + + }; + break; + } + case 1: + { + // whirlwind + whirlwindCenter = UnityEngine.Random.insideUnitCircle * UnityEngine.Random.Range(0, 6.0f); + whirlwindRadius = UnityEngine.Random.Range(3.0f, 4.0f); + float maxWhirlwindForce = UnityEngine.Random.Range(1.0f, 1.6f); + float maxWhirlwindForceUp = UnityEngine.Random.Range(0.3f, 0.8f); + + float fadeTime = UnityEngine.Random.Range(2.0f, 4.0f); + float windTime = UnityEngine.Random.Range(6.0f, 8.0f); + + Debug.LogError("WHIRLWIND: C:" + whirlwindCenter + " R:" + whirlwindRadius + " F:" + maxWhirlwindForce + " U:" + maxWhirlwindForceUp + " F:" + fadeTime + " T:" + windTime); + + tween.Init(v => + { + whirlwindForce = maxWhirlwindForce * v; + whirlwindForceUp = maxWhirlwindForceUp * v; + }, SimpleTween.EaseLinear, 0, 1, fadeTime); + tween.OnFinish = () => + { + tween.Init(v => + { + //windForce = windVector * windStrength * (Mathf.Sin(v * 25) + 1) * 0.2f; + }, SimpleTween.EaseLinear, 0, windTime, windTime); + tween.OnFinish = () => + { + tween.Init(v => + { + whirlwindForce = maxWhirlwindForce * v; + whirlwindForceUp = maxWhirlwindForceUp * v; + }, SimpleTween.EaseLinear, 1, 0, fadeTime); + tween.OnFinish = () => + { + WaitForNextEvent(); + }; + }; + + }; + + break; + } + } + } + + // Update is called once per frame + void Update () { + bool hasWind = windForce.sqrMagnitude > 0.00001f; + bool hasWhirlwind = whirlwindForce > 0; + Vector2 windDir = new Vector2(windForce.x, windForce.y); + windDir.Normalize(); + + float distAway = 9.0f; + + + foreach (LeafPhysics leaf in leafs) + { + if (hasWind && (UnityEngine.Random.Range(0, 1f) < 0.25f || !leaf.Resting)) + { + float amount = Vector2.Dot(new Vector2(leaf.Body.velocity.x, leaf.Body.velocity.z), windDir); + amount = Math.Max(0, Math.Min(1, 8 - amount)); + leaf.Body.AddForce(new Vector3(windForce.x * UnityEngine.Random.Range(0.75f, 1.0f), + windForce.y * UnityEngine.Random.Range(0.9f, 1.0f), + windForce.z * UnityEngine.Random.Range(0.75f, 1.0f)) * Time.deltaTime * 60 * (leaf.Resting ? 3.0f : 0.4f)); + } + Vector2 d = new Vector2(leaf.transform.position.x, leaf.transform.position.z); + + if (hasWhirlwind && (UnityEngine.Random.Range(0, 1f) < 0.15f || !leaf.Resting)) + { + Vector2 offset = new Vector2(leaf.transform.position.x, leaf.transform.position.z) - whirlwindCenter; + Vector2 offsetN = offset.normalized; + float distFrom = offset.magnitude; + + if (distFrom < whirlwindRadius) + { + + Vector2 tangent = new Vector2(-offsetN.y, offsetN.x); + Vector2 force = tangent * (whirlwindRadius - distFrom) * whirlwindForce + offset * -0.9f; + + Vector3 force3D = new Vector3(force.x, whirlwindForceUp * (whirlwindRadius - distFrom + 2), force.y); + + leaf.Body.AddForce(new Vector3(force3D.x * UnityEngine.Random.Range(0.75f, 1.0f), + force3D.y * UnityEngine.Random.Range(0.9f, 1.0f), + force3D.z * UnityEngine.Random.Range(0.75f, 1.0f)) * Time.deltaTime * 60 * (leaf.Resting ? 3.0f : 0.4f)); + + } + + + } + + if (d.magnitude > distAway && !leaf.Resting) + { + //leaf.Body.apply + } + } + + } +} diff --git a/FallUnity/Assets/Leaves/LeafPhysics.cs b/FallUnity/Assets/Leaves/LeafPhysics.cs index 3355523..d59bfba 100755 --- a/FallUnity/Assets/Leaves/LeafPhysics.cs +++ b/FallUnity/Assets/Leaves/LeafPhysics.cs @@ -9,6 +9,10 @@ public Rigidbody Body { get { return body; } } private LeafHandler leafHandler; + + private List mats = new List(); + public IEnumerable Mats { get { return mats; } } + // Use this for initialization void Start () { body = GetComponentInChildren(); @@ -23,18 +27,32 @@ leafHandler = GameObject.FindObjectOfType(); if (leafHandler != null) { - leafHandler.AddLeaf(); + leafHandler.AddLeaf(this); } - deadLifeSpan = UnityEngine.Random.Range(20, 40); + deadLifeSpan = UnityEngine.Random.Range(20, 40.0f); deadLife = deadLifeSpan; + + foreach (MeshRenderer mr in GetComponentsInChildren()) + { + mats.Add(mr.material); + } + + Color c = Color.white; + c.r = UnityEngine.Random.Range(0.6f, 1.0f); + c.g = UnityEngine.Random.Range(0.6f, 1.0f); + c.b = UnityEngine.Random.Range(0.6f, 1.0f); + foreach (Material m in mats) + { + m.color = c; + } } void OnDestroy() { if (leafHandler != null) { - leafHandler.RemoveLeaf(); + leafHandler.RemoveLeaf(this); } } @@ -109,6 +127,17 @@ private bool isFading = false; + public bool Resting = false; + private void FixedUpdate() + { + Resting = false; + } + + private void OnCollisionStay(Collision collision) + { + Resting = collision.contacts.Length > 0 && Mathf.Abs(collision.contacts[0].normal.y) > 0.7f; + } + // Update is called once per frame void Update () { if (!body.isKinematic && body.velocity.sqrMagnitude > 0.01f) @@ -145,16 +174,11 @@ } else { - deadLife -= Time.deltaTime; + deadLife -= Time.deltaTime * (leafHandler.NumLeaves >= leafHandler.MaxLeaves ? 3 : 1); if (deadLife <= 0 && !isFading) { isFading = true; SimpleTween tweenOut = new SimpleTween(); - HashSet mats = new HashSet(); - foreach (MeshRenderer mr in GetComponentsInChildren()) - { - mats.Add(mr.material); - } tweenOut.Init(v => { foreach (Material m in mats) diff --git a/FallUnity/Assets/Leaves/Pile.cs b/FallUnity/Assets/Leaves/Pile.cs new file mode 100644 index 0000000..47b81a1 --- /dev/null +++ b/FallUnity/Assets/Leaves/Pile.cs @@ -0,0 +1,16 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Pile : MonoBehaviour { + public int NumLeaves = 0; + // Use this for initialization + void Start () { + + } + + // Update is called once per frame + void Update () { + + } +} diff --git a/FallUnity/Assets/Leaves/Pile.cs.meta b/FallUnity/Assets/Leaves/Pile.cs.meta new file mode 100644 index 0000000..46f4782 --- /dev/null +++ b/FallUnity/Assets/Leaves/Pile.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 9aba3a790a516f143a6189a050883fe6 +timeCreated: 1572217739 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/FallUnity/Assets/Leaves/Pile.prefab b/FallUnity/Assets/Leaves/Pile.prefab index c9e6823..7399566 100644 --- a/FallUnity/Assets/Leaves/Pile.prefab +++ b/FallUnity/Assets/Leaves/Pile.prefab @@ -46,7 +46,7 @@ m_IsActive: 1 --- !u!1 &1455629288405468 GameObject: - m_ObjectHideFlags: 0 + m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} serializedVersion: 5 @@ -60,13 +60,28 @@ m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!1 &1865097145533800 +--- !u!1 &1676669835933754 GameObject: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} serializedVersion: 5 m_Component: + - component: {fileID: 4516590634453678} + m_Layer: 0 + m_Name: PileHolder + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!1 &1865097145533800 +GameObject: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 5 + m_Component: - component: {fileID: 4637029664340020} m_Layer: 0 m_Name: Mesh @@ -81,12 +96,11 @@ m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1430576817403556} - m_LocalRotation: {x: 0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -0.6, y: -1.1, z: 4.45} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: -1.13, y: 6.12, z: 8.16} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - - {fileID: 4637029664340020} - - {fileID: 4794401915724672} + - {fileID: 4516590634453678} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -103,18 +117,33 @@ m_Father: {fileID: 4637029664340020} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!4 &4516590634453678 +Transform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1676669835933754} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 4637029664340020} + - {fileID: 4794401915724672} + m_Father: {fileID: 4028432306176728} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!4 &4637029664340020 Transform: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1865097145533800} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0.5187102, y: 0.51870996, z: 0.51870996} m_Children: - {fileID: 4097242592220890} - m_Father: {fileID: 4028432306176728} + m_Father: {fileID: 4516590634453678} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!4 &4794401915724672 @@ -123,11 +152,11 @@ m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1455629288405468} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0.5187102, y: 0.51870996, z: 0.51870996} m_Children: [] - m_Father: {fileID: 4028432306176728} + m_Father: {fileID: 4516590634453678} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!23 &23658430294834434 diff --git a/FallUnity/Assets/Player/Player.prefab b/FallUnity/Assets/Player/Player.prefab index c9796b0..c6f5428 100644 --- a/FallUnity/Assets/Player/Player.prefab +++ b/FallUnity/Assets/Player/Player.prefab @@ -236,7 +236,9 @@ RakeBackTime: 0.15 RakeReachDist: 0.7 RakeReachRadius: 0.8 - RakeFlyForce: 100 + RakeFlyForce: 2.02 + PilePrefab: {fileID: 1430576817403556, guid: d6cf61ddfecafa14991e99ec6f1e33f0, type: 2} + PileSearchRadius: 0.7 --- !u!114 &114917061756029764 MonoBehaviour: m_ObjectHideFlags: 1 diff --git a/FallUnity/Assets/Player/PlayerController.cs b/FallUnity/Assets/Player/PlayerController.cs index a463e36..e5dd76c 100755 --- a/FallUnity/Assets/Player/PlayerController.cs +++ b/FallUnity/Assets/Player/PlayerController.cs @@ -12,11 +12,14 @@ public enum State { Walking, - Raking + Raking, + MakingPile } private State state = State.Walking; + private int leafLayer = 0; + private CharacterController charC; private AnimationHandler anim; // Use this for initialization @@ -27,6 +30,8 @@ rakeBackTween = new SimpleTween(); oldPos = transform.position; + leafLayer = LayerMask.GetMask("leaf"); + } private float velY = 0; @@ -51,6 +56,10 @@ private Vector3 oldPos = new Vector3(); + private Vector3 playerDir = new Vector3(); + + public int[] LeafsForPile; + // Update is called once per frame void Update () { @@ -60,12 +69,17 @@ { if (charC.isGrounded && state == State.Walking) { + dir.x = input.Axis(InputSource.InputAxis.MoveX); - dir.z = input.Axis(InputSource.InputAxis.MoveY); + dir.z = input.Axis(InputSource.InputAxis.MoveY); if (dir.magnitude > 0.3f) { dir.Normalize(); + + playerDir.x = dir.x; + playerDir.y = dir.y; + float speed = Speed; if (runCycle < RunFrameTime) { @@ -119,9 +133,8 @@ Vector3 moved = transform.position - oldPos; if (moved.magnitude > 0.7f * Time.deltaTime) - { - int layer = LayerMask.GetMask("leaf"); - foreach (Collider c in Physics.OverlapSphere(transform.position, PushRadius, layer)) + { + foreach (Collider c in Physics.OverlapSphere(transform.position, PushRadius, leafLayer)) { LeafPhysics leaf = c.GetComponentInParent(); if (leaf != null) @@ -136,8 +149,8 @@ } } - rakeDir = new Vector3(input.Axis(InputSource.InputAxis.RakeX), 0, input.Axis(InputSource.InputAxis.RakeY)); - if (rakeDir.magnitude < 0.2f) + Vector3 localRakeDir = new Vector3(input.Axis(InputSource.InputAxis.RakeX), 0, input.Axis(InputSource.InputAxis.RakeY)); + if (localRakeDir.magnitude < 0.2f) { rakeTime = 0; } @@ -149,8 +162,9 @@ } } - if (rakeTime >= 0 && rakeDir.magnitude > 0.7f && rakeTime < TimeToPushRake) + if (rakeTime >= 0 && localRakeDir.magnitude > 0.7f && rakeTime < TimeToPushRake) { + rakeDir = localRakeDir; state = State.Raking; float angle = Mathf.Atan2(-rakeDir.z, -rakeDir.x); @@ -170,6 +184,29 @@ rakeTimer.Start(0.15f, Rake); } + + if (state == State.Walking && input.ButtonPressedThisFrame(InputSource.InputButton.MakePile)) + { + rakeDir = playerDir; + state = State.MakingPile; + + float angle = Mathf.Atan2(-rakeDir.z, -rakeDir.x); + + if (angle < 0) angle += Mathf.PI * 2; + + AnimationHandler.Direction rakeAnimDir = AnimationHandler.Direction.UpRight; + + if (angle < Mathf.PI / 2.0f) rakeAnimDir = AnimationHandler.Direction.UpRight; + if (angle < Mathf.PI && angle >= Mathf.PI / 2.0f) rakeAnimDir = AnimationHandler.Direction.UpLeft; + if (angle < Mathf.PI * 3.0f / 2.0f && angle >= Mathf.PI) rakeAnimDir = AnimationHandler.Direction.DownLeft; + if (angle >= Mathf.PI * 3.0f / 2.0f) rakeAnimDir = AnimationHandler.Direction.DownRight; + + rakeTime = -1; + + anim.SetState("Rake", rakeAnimDir, 0); + + rakeTimer.Start(0.35f, MakePile); + } } oldPos = transform.position; @@ -200,8 +237,6 @@ rakeBackTween.Init(UpdateRakeBack, SimpleTween.QuadEaseInOut, 0, 1, RakeBackTime); rakeBackTween.OnFinish = FinishedRake; - rakeTimer.Start(RakeBackTime * 1.5f, CheckPile); - List leafs = new List(); int layer = LayerMask.GetMask("leaf"); @@ -216,14 +251,14 @@ foreach (LeafPhysics leaf in leafs) { - float rand = UnityEngine.Random.Range(0, 1); + float rand = UnityEngine.Random.Range(0, 1.0f); Vector3 startPos = leaf.transform.position; Vector3 toLeaf = startPos - transform.position; float dist = Vector3.Dot(toLeaf, -rakeDir); dist += UnityEngine.Random.Range(-0.1f, 0.1f); Vector3 pull = rakeDir * dist; - if (rand < 0.6f) + if (rand < 0.5f) { // pull the leaf back, and then destroy @@ -238,40 +273,59 @@ SimpleTween tween = new SimpleTween(v => { - leaf.transform.position = startPos + pull * v; + if (leaf != null) + { + leaf.transform.position = startPos + pull * v; + } }, SimpleTween.TweenType.EaseLinear, 0, 1, pullTime); tween.OnFinish = () => { - leaf.Body.isKinematic = false; + if (leaf != null) + { + leaf.Body.isKinematic = false; + } //GameObject.Destroy(leaf.gameObject); }; } - else if (rand < 0.8f) + else if (rand < 0.7f) { pull.Normalize(); - pull = Quaternion.Euler(UnityEngine.Random.Range(-30, 30), UnityEngine.Random.Range(-30, 30), UnityEngine.Random.Range(-30, 30)) * pull; + pull = Quaternion.Euler(UnityEngine.Random.Range(-30.0f, 30.0f), UnityEngine.Random.Range(-30.0f, 30.0f), UnityEngine.Random.Range(-30.0f, 30.0f)) * pull; pull.y += 0.3f; leaf.Body.AddForce(pull * RakeFlyForce, ForceMode.Impulse); } else { - } } } public GameObject PilePrefab; - private void CheckPile() + public float PileSearchRadius = 0.7f; + + private List potentialPile = new List(); + private void MakePile() { - + anim.SetState("Stand", anim.Dir, 0); + potentialPile.Clear(); + foreach (Collider c in Physics.OverlapSphere(transform.position + rakeDir * RakeReachDist, PileSearchRadius, leafLayer)) + { + LeafPhysics leaf = c.GetComponentInParent(); + if (leaf != null) + { + potentialPile.Add(leaf); + } + } + + } private void FinishedRake() { state = State.Walking; - anim.SetState("Stand", anim.Dir, anim.Frame); + anim.SetState("Stand", anim.Dir, 0); } private void UpdateRakeBack(float val) diff --git a/FallUnity/Assets/PlayerInput/InputSource.cs b/FallUnity/Assets/PlayerInput/InputSource.cs index 2cccceb..8cf23ec 100644 --- a/FallUnity/Assets/PlayerInput/InputSource.cs +++ b/FallUnity/Assets/PlayerInput/InputSource.cs @@ -12,6 +12,9 @@ { MenuSelect, MenuCancel, + + MakePile, + DestroyPile } public enum InputAxis diff --git a/FallUnity/Assets/PlayerInput/KeyboardMouseInputSource.cs b/FallUnity/Assets/PlayerInput/KeyboardMouseInputSource.cs index fc97956..9ea58d2 100644 --- a/FallUnity/Assets/PlayerInput/KeyboardMouseInputSource.cs +++ b/FallUnity/Assets/PlayerInput/KeyboardMouseInputSource.cs @@ -41,7 +41,8 @@ { InputButton.MenuSelect, KeyCode.Return }, { InputButton.MenuCancel, KeyCode.Escape }, - //{ InputButton.UseItem, KeyCode.Space }, + { InputButton.MakePile, KeyCode.Space }, + { InputButton.DestroyPile, KeyCode.Backspace }, //{ InputButton.PickA, KeyCode.Q }, //{ InputButton.PickB, KeyCode.E }, diff --git a/FallUnity/Assets/PlayerInput/XboxControllerInputSource.cs b/FallUnity/Assets/PlayerInput/XboxControllerInputSource.cs index 1106813..d82bfcd 100644 --- a/FallUnity/Assets/PlayerInput/XboxControllerInputSource.cs +++ b/FallUnity/Assets/PlayerInput/XboxControllerInputSource.cs @@ -37,7 +37,8 @@ { InputButton.MenuSelect, XboxButton.A }, { InputButton.MenuCancel, XboxButton.B }, - //{ InputButton.UseItem, XboxButton.A }, + { InputButton.MakePile, XboxButton.A }, + { InputButton.DestroyPile, XboxButton.B }, //{ InputButton.PickA, XboxButton.LeftBumper }, //{ InputButton.PickB, XboxButton.RightBumper }, diff --git a/Build/fall_Data/Managed/Assembly-CSharp.dll b/Build/fall_Data/Managed/Assembly-CSharp.dll index 473b708..7e14020 100644 --- a/Build/fall_Data/Managed/Assembly-CSharp.dll +++ b/Build/fall_Data/Managed/Assembly-CSharp.dll Binary files differ diff --git a/Build/fall_Data/globalgamemanagers b/Build/fall_Data/globalgamemanagers index 4e34461..e79341a 100644 --- a/Build/fall_Data/globalgamemanagers +++ b/Build/fall_Data/globalgamemanagers Binary files differ diff --git a/Build/fall_Data/globalgamemanagers.assets b/Build/fall_Data/globalgamemanagers.assets index f90a19e..8cb05c1 100644 --- a/Build/fall_Data/globalgamemanagers.assets +++ b/Build/fall_Data/globalgamemanagers.assets Binary files differ diff --git a/Build/fall_Data/level0 b/Build/fall_Data/level0 index f49aed1..4a45106 100644 --- a/Build/fall_Data/level0 +++ b/Build/fall_Data/level0 Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets b/Build/fall_Data/sharedassets0.assets index da4c84e..3e933fc 100644 --- a/Build/fall_Data/sharedassets0.assets +++ b/Build/fall_Data/sharedassets0.assets Binary files differ diff --git a/Build/fall_Data/sharedassets0.assets.resS b/Build/fall_Data/sharedassets0.assets.resS index 811ed41..091e899 100644 --- a/Build/fall_Data/sharedassets0.assets.resS +++ b/Build/fall_Data/sharedassets0.assets.resS Binary files differ diff --git a/FallUnity/Assets/Game/LeafSpawner.cs b/FallUnity/Assets/Game/LeafSpawner.cs index dd7cba9..beeff78 100644 --- a/FallUnity/Assets/Game/LeafSpawner.cs +++ b/FallUnity/Assets/Game/LeafSpawner.cs @@ -22,11 +22,13 @@ time += Time.deltaTime; while (time > interval) { + time -= interval; if (leafHandler != null && leafHandler.NumLeaves < leafHandler.MaxLeaves) - { - time -= interval; - Vector2 offset = Random.insideUnitCircle; - Vector3 point = transform.position + new Vector3(offset.x * Radius, 0, offset.y * Radius); + { + float angle = UnityEngine.Random.Range(0, Mathf.PI * 2); + float r = UnityEngine.Random.Range(0, Radius); + + Vector3 point = transform.position + new Vector3(Mathf.Sin(angle) * r, 0, Mathf.Cos(angle) * r); LeafPhysics leaf = GameObject.Instantiate(Leafs[Random.Range(0, Leafs.Length)]); leaves.Add(leaf); leaf.transform.position = point; diff --git a/FallUnity/Assets/Leaves/LeafHandler.cs b/FallUnity/Assets/Leaves/LeafHandler.cs index f931ce3..8ba3c89 100644 --- a/FallUnity/Assets/Leaves/LeafHandler.cs +++ b/FallUnity/Assets/Leaves/LeafHandler.cs @@ -1,28 +1,183 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class LeafHandler : MonoBehaviour { - private int numLeaves = 0; - public int NumLeaves { get { return numLeaves; } } - public int MaxLeaves = 700; - - public void AddLeaf() +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class LeafHandler : MonoBehaviour { + public int NumLeaves = 0; + public int MaxLeaves = 700; + + private HashSet leafs = new HashSet(); + + public void AddLeaf(LeafPhysics l) { - numLeaves++; - } - - public void RemoveLeaf() - { - numLeaves--; + leafs.Add(l); + NumLeaves = leafs.Count; } + + public void RemoveLeaf(LeafPhysics l) + { + leafs.Remove(l); + NumLeaves = leafs.Count; + } + + private SimpleTimer timer; + private SimpleTween tween; // Use this for initialization - void Start () { - - } - - // Update is called once per frame - void Update () { - - } -} + void Start () { + timer = new SimpleTimer(); + tween = new SimpleTween(); + //WaitForNextEvent(); + PickNextEvent(); + } + + private void WaitForNextEvent() + { + timer.Start(UnityEngine.Random.Range(7.0f, 20.0f), PickNextEvent); + } + + private Vector3 windForce = new Vector3(); + private Vector2 whirlwindCenter = new Vector3(); + private float whirlwindRadius = 0; + private float whirlwindForce = 0; + private float whirlwindForceUp = 0; + + private void PickNextEvent() + { + int eventType = UnityEngine.Random.Range(0, 2); + switch (eventType) + { + case 0: + { + // wind + float windAngle = UnityEngine.Random.Range(0, Mathf.PI * 2); + Vector3 windVector = new Vector3(Mathf.Sin(windAngle), 0, Mathf.Cos(windAngle)); + windVector.y = UnityEngine.Random.Range(0.8f, 1.2f); + float windStrength = UnityEngine.Random.Range(0.8f, 1.3f); + float fadeTime = UnityEngine.Random.Range(1.0f, 3.0f); + float windTime = UnityEngine.Random.Range(3.0f, 5.0f); + + Debug.LogError("WIND: V:" + windVector + " S:" + windStrength + " F:" + fadeTime + " T:" + windTime); + + tween.Init(v => + { + windForce = windVector * windStrength * v; + }, SimpleTween.EaseLinear, 0, 1, fadeTime); + tween.OnFinish = () => + { + tween.Init(v => + { + //windForce = windVector * windStrength * (Mathf.Sin(v * 25) + 1) * 0.2f; + }, SimpleTween.EaseLinear, 0, windTime, windTime); + tween.OnFinish = () => + { + tween.Init(v => + { + windForce = windVector * windStrength * v; + }, SimpleTween.EaseLinear, 1, 0, fadeTime); + tween.OnFinish = () => + { + WaitForNextEvent(); + }; + }; + + }; + break; + } + case 1: + { + // whirlwind + whirlwindCenter = UnityEngine.Random.insideUnitCircle * UnityEngine.Random.Range(0, 6.0f); + whirlwindRadius = UnityEngine.Random.Range(3.0f, 4.0f); + float maxWhirlwindForce = UnityEngine.Random.Range(1.0f, 1.6f); + float maxWhirlwindForceUp = UnityEngine.Random.Range(0.3f, 0.8f); + + float fadeTime = UnityEngine.Random.Range(2.0f, 4.0f); + float windTime = UnityEngine.Random.Range(6.0f, 8.0f); + + Debug.LogError("WHIRLWIND: C:" + whirlwindCenter + " R:" + whirlwindRadius + " F:" + maxWhirlwindForce + " U:" + maxWhirlwindForceUp + " F:" + fadeTime + " T:" + windTime); + + tween.Init(v => + { + whirlwindForce = maxWhirlwindForce * v; + whirlwindForceUp = maxWhirlwindForceUp * v; + }, SimpleTween.EaseLinear, 0, 1, fadeTime); + tween.OnFinish = () => + { + tween.Init(v => + { + //windForce = windVector * windStrength * (Mathf.Sin(v * 25) + 1) * 0.2f; + }, SimpleTween.EaseLinear, 0, windTime, windTime); + tween.OnFinish = () => + { + tween.Init(v => + { + whirlwindForce = maxWhirlwindForce * v; + whirlwindForceUp = maxWhirlwindForceUp * v; + }, SimpleTween.EaseLinear, 1, 0, fadeTime); + tween.OnFinish = () => + { + WaitForNextEvent(); + }; + }; + + }; + + break; + } + } + } + + // Update is called once per frame + void Update () { + bool hasWind = windForce.sqrMagnitude > 0.00001f; + bool hasWhirlwind = whirlwindForce > 0; + Vector2 windDir = new Vector2(windForce.x, windForce.y); + windDir.Normalize(); + + float distAway = 9.0f; + + + foreach (LeafPhysics leaf in leafs) + { + if (hasWind && (UnityEngine.Random.Range(0, 1f) < 0.25f || !leaf.Resting)) + { + float amount = Vector2.Dot(new Vector2(leaf.Body.velocity.x, leaf.Body.velocity.z), windDir); + amount = Math.Max(0, Math.Min(1, 8 - amount)); + leaf.Body.AddForce(new Vector3(windForce.x * UnityEngine.Random.Range(0.75f, 1.0f), + windForce.y * UnityEngine.Random.Range(0.9f, 1.0f), + windForce.z * UnityEngine.Random.Range(0.75f, 1.0f)) * Time.deltaTime * 60 * (leaf.Resting ? 3.0f : 0.4f)); + } + Vector2 d = new Vector2(leaf.transform.position.x, leaf.transform.position.z); + + if (hasWhirlwind && (UnityEngine.Random.Range(0, 1f) < 0.15f || !leaf.Resting)) + { + Vector2 offset = new Vector2(leaf.transform.position.x, leaf.transform.position.z) - whirlwindCenter; + Vector2 offsetN = offset.normalized; + float distFrom = offset.magnitude; + + if (distFrom < whirlwindRadius) + { + + Vector2 tangent = new Vector2(-offsetN.y, offsetN.x); + Vector2 force = tangent * (whirlwindRadius - distFrom) * whirlwindForce + offset * -0.9f; + + Vector3 force3D = new Vector3(force.x, whirlwindForceUp * (whirlwindRadius - distFrom + 2), force.y); + + leaf.Body.AddForce(new Vector3(force3D.x * UnityEngine.Random.Range(0.75f, 1.0f), + force3D.y * UnityEngine.Random.Range(0.9f, 1.0f), + force3D.z * UnityEngine.Random.Range(0.75f, 1.0f)) * Time.deltaTime * 60 * (leaf.Resting ? 3.0f : 0.4f)); + + } + + + } + + if (d.magnitude > distAway && !leaf.Resting) + { + //leaf.Body.apply + } + } + + } +} diff --git a/FallUnity/Assets/Leaves/LeafPhysics.cs b/FallUnity/Assets/Leaves/LeafPhysics.cs index 3355523..d59bfba 100755 --- a/FallUnity/Assets/Leaves/LeafPhysics.cs +++ b/FallUnity/Assets/Leaves/LeafPhysics.cs @@ -9,6 +9,10 @@ public Rigidbody Body { get { return body; } } private LeafHandler leafHandler; + + private List mats = new List(); + public IEnumerable Mats { get { return mats; } } + // Use this for initialization void Start () { body = GetComponentInChildren(); @@ -23,18 +27,32 @@ leafHandler = GameObject.FindObjectOfType(); if (leafHandler != null) { - leafHandler.AddLeaf(); + leafHandler.AddLeaf(this); } - deadLifeSpan = UnityEngine.Random.Range(20, 40); + deadLifeSpan = UnityEngine.Random.Range(20, 40.0f); deadLife = deadLifeSpan; + + foreach (MeshRenderer mr in GetComponentsInChildren()) + { + mats.Add(mr.material); + } + + Color c = Color.white; + c.r = UnityEngine.Random.Range(0.6f, 1.0f); + c.g = UnityEngine.Random.Range(0.6f, 1.0f); + c.b = UnityEngine.Random.Range(0.6f, 1.0f); + foreach (Material m in mats) + { + m.color = c; + } } void OnDestroy() { if (leafHandler != null) { - leafHandler.RemoveLeaf(); + leafHandler.RemoveLeaf(this); } } @@ -109,6 +127,17 @@ private bool isFading = false; + public bool Resting = false; + private void FixedUpdate() + { + Resting = false; + } + + private void OnCollisionStay(Collision collision) + { + Resting = collision.contacts.Length > 0 && Mathf.Abs(collision.contacts[0].normal.y) > 0.7f; + } + // Update is called once per frame void Update () { if (!body.isKinematic && body.velocity.sqrMagnitude > 0.01f) @@ -145,16 +174,11 @@ } else { - deadLife -= Time.deltaTime; + deadLife -= Time.deltaTime * (leafHandler.NumLeaves >= leafHandler.MaxLeaves ? 3 : 1); if (deadLife <= 0 && !isFading) { isFading = true; SimpleTween tweenOut = new SimpleTween(); - HashSet mats = new HashSet(); - foreach (MeshRenderer mr in GetComponentsInChildren()) - { - mats.Add(mr.material); - } tweenOut.Init(v => { foreach (Material m in mats) diff --git a/FallUnity/Assets/Leaves/Pile.cs b/FallUnity/Assets/Leaves/Pile.cs new file mode 100644 index 0000000..47b81a1 --- /dev/null +++ b/FallUnity/Assets/Leaves/Pile.cs @@ -0,0 +1,16 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Pile : MonoBehaviour { + public int NumLeaves = 0; + // Use this for initialization + void Start () { + + } + + // Update is called once per frame + void Update () { + + } +} diff --git a/FallUnity/Assets/Leaves/Pile.cs.meta b/FallUnity/Assets/Leaves/Pile.cs.meta new file mode 100644 index 0000000..46f4782 --- /dev/null +++ b/FallUnity/Assets/Leaves/Pile.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 9aba3a790a516f143a6189a050883fe6 +timeCreated: 1572217739 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/FallUnity/Assets/Leaves/Pile.prefab b/FallUnity/Assets/Leaves/Pile.prefab index c9e6823..7399566 100644 --- a/FallUnity/Assets/Leaves/Pile.prefab +++ b/FallUnity/Assets/Leaves/Pile.prefab @@ -46,7 +46,7 @@ m_IsActive: 1 --- !u!1 &1455629288405468 GameObject: - m_ObjectHideFlags: 0 + m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} serializedVersion: 5 @@ -60,13 +60,28 @@ m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!1 &1865097145533800 +--- !u!1 &1676669835933754 GameObject: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} serializedVersion: 5 m_Component: + - component: {fileID: 4516590634453678} + m_Layer: 0 + m_Name: PileHolder + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!1 &1865097145533800 +GameObject: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 5 + m_Component: - component: {fileID: 4637029664340020} m_Layer: 0 m_Name: Mesh @@ -81,12 +96,11 @@ m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1430576817403556} - m_LocalRotation: {x: 0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -0.6, y: -1.1, z: 4.45} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: -1.13, y: 6.12, z: 8.16} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - - {fileID: 4637029664340020} - - {fileID: 4794401915724672} + - {fileID: 4516590634453678} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -103,18 +117,33 @@ m_Father: {fileID: 4637029664340020} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!4 &4516590634453678 +Transform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1676669835933754} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 4637029664340020} + - {fileID: 4794401915724672} + m_Father: {fileID: 4028432306176728} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!4 &4637029664340020 Transform: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1865097145533800} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0.5187102, y: 0.51870996, z: 0.51870996} m_Children: - {fileID: 4097242592220890} - m_Father: {fileID: 4028432306176728} + m_Father: {fileID: 4516590634453678} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!4 &4794401915724672 @@ -123,11 +152,11 @@ m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1455629288405468} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0.5187102, y: 0.51870996, z: 0.51870996} m_Children: [] - m_Father: {fileID: 4028432306176728} + m_Father: {fileID: 4516590634453678} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!23 &23658430294834434 diff --git a/FallUnity/Assets/Player/Player.prefab b/FallUnity/Assets/Player/Player.prefab index c9796b0..c6f5428 100644 --- a/FallUnity/Assets/Player/Player.prefab +++ b/FallUnity/Assets/Player/Player.prefab @@ -236,7 +236,9 @@ RakeBackTime: 0.15 RakeReachDist: 0.7 RakeReachRadius: 0.8 - RakeFlyForce: 100 + RakeFlyForce: 2.02 + PilePrefab: {fileID: 1430576817403556, guid: d6cf61ddfecafa14991e99ec6f1e33f0, type: 2} + PileSearchRadius: 0.7 --- !u!114 &114917061756029764 MonoBehaviour: m_ObjectHideFlags: 1 diff --git a/FallUnity/Assets/Player/PlayerController.cs b/FallUnity/Assets/Player/PlayerController.cs index a463e36..e5dd76c 100755 --- a/FallUnity/Assets/Player/PlayerController.cs +++ b/FallUnity/Assets/Player/PlayerController.cs @@ -12,11 +12,14 @@ public enum State { Walking, - Raking + Raking, + MakingPile } private State state = State.Walking; + private int leafLayer = 0; + private CharacterController charC; private AnimationHandler anim; // Use this for initialization @@ -27,6 +30,8 @@ rakeBackTween = new SimpleTween(); oldPos = transform.position; + leafLayer = LayerMask.GetMask("leaf"); + } private float velY = 0; @@ -51,6 +56,10 @@ private Vector3 oldPos = new Vector3(); + private Vector3 playerDir = new Vector3(); + + public int[] LeafsForPile; + // Update is called once per frame void Update () { @@ -60,12 +69,17 @@ { if (charC.isGrounded && state == State.Walking) { + dir.x = input.Axis(InputSource.InputAxis.MoveX); - dir.z = input.Axis(InputSource.InputAxis.MoveY); + dir.z = input.Axis(InputSource.InputAxis.MoveY); if (dir.magnitude > 0.3f) { dir.Normalize(); + + playerDir.x = dir.x; + playerDir.y = dir.y; + float speed = Speed; if (runCycle < RunFrameTime) { @@ -119,9 +133,8 @@ Vector3 moved = transform.position - oldPos; if (moved.magnitude > 0.7f * Time.deltaTime) - { - int layer = LayerMask.GetMask("leaf"); - foreach (Collider c in Physics.OverlapSphere(transform.position, PushRadius, layer)) + { + foreach (Collider c in Physics.OverlapSphere(transform.position, PushRadius, leafLayer)) { LeafPhysics leaf = c.GetComponentInParent(); if (leaf != null) @@ -136,8 +149,8 @@ } } - rakeDir = new Vector3(input.Axis(InputSource.InputAxis.RakeX), 0, input.Axis(InputSource.InputAxis.RakeY)); - if (rakeDir.magnitude < 0.2f) + Vector3 localRakeDir = new Vector3(input.Axis(InputSource.InputAxis.RakeX), 0, input.Axis(InputSource.InputAxis.RakeY)); + if (localRakeDir.magnitude < 0.2f) { rakeTime = 0; } @@ -149,8 +162,9 @@ } } - if (rakeTime >= 0 && rakeDir.magnitude > 0.7f && rakeTime < TimeToPushRake) + if (rakeTime >= 0 && localRakeDir.magnitude > 0.7f && rakeTime < TimeToPushRake) { + rakeDir = localRakeDir; state = State.Raking; float angle = Mathf.Atan2(-rakeDir.z, -rakeDir.x); @@ -170,6 +184,29 @@ rakeTimer.Start(0.15f, Rake); } + + if (state == State.Walking && input.ButtonPressedThisFrame(InputSource.InputButton.MakePile)) + { + rakeDir = playerDir; + state = State.MakingPile; + + float angle = Mathf.Atan2(-rakeDir.z, -rakeDir.x); + + if (angle < 0) angle += Mathf.PI * 2; + + AnimationHandler.Direction rakeAnimDir = AnimationHandler.Direction.UpRight; + + if (angle < Mathf.PI / 2.0f) rakeAnimDir = AnimationHandler.Direction.UpRight; + if (angle < Mathf.PI && angle >= Mathf.PI / 2.0f) rakeAnimDir = AnimationHandler.Direction.UpLeft; + if (angle < Mathf.PI * 3.0f / 2.0f && angle >= Mathf.PI) rakeAnimDir = AnimationHandler.Direction.DownLeft; + if (angle >= Mathf.PI * 3.0f / 2.0f) rakeAnimDir = AnimationHandler.Direction.DownRight; + + rakeTime = -1; + + anim.SetState("Rake", rakeAnimDir, 0); + + rakeTimer.Start(0.35f, MakePile); + } } oldPos = transform.position; @@ -200,8 +237,6 @@ rakeBackTween.Init(UpdateRakeBack, SimpleTween.QuadEaseInOut, 0, 1, RakeBackTime); rakeBackTween.OnFinish = FinishedRake; - rakeTimer.Start(RakeBackTime * 1.5f, CheckPile); - List leafs = new List(); int layer = LayerMask.GetMask("leaf"); @@ -216,14 +251,14 @@ foreach (LeafPhysics leaf in leafs) { - float rand = UnityEngine.Random.Range(0, 1); + float rand = UnityEngine.Random.Range(0, 1.0f); Vector3 startPos = leaf.transform.position; Vector3 toLeaf = startPos - transform.position; float dist = Vector3.Dot(toLeaf, -rakeDir); dist += UnityEngine.Random.Range(-0.1f, 0.1f); Vector3 pull = rakeDir * dist; - if (rand < 0.6f) + if (rand < 0.5f) { // pull the leaf back, and then destroy @@ -238,40 +273,59 @@ SimpleTween tween = new SimpleTween(v => { - leaf.transform.position = startPos + pull * v; + if (leaf != null) + { + leaf.transform.position = startPos + pull * v; + } }, SimpleTween.TweenType.EaseLinear, 0, 1, pullTime); tween.OnFinish = () => { - leaf.Body.isKinematic = false; + if (leaf != null) + { + leaf.Body.isKinematic = false; + } //GameObject.Destroy(leaf.gameObject); }; } - else if (rand < 0.8f) + else if (rand < 0.7f) { pull.Normalize(); - pull = Quaternion.Euler(UnityEngine.Random.Range(-30, 30), UnityEngine.Random.Range(-30, 30), UnityEngine.Random.Range(-30, 30)) * pull; + pull = Quaternion.Euler(UnityEngine.Random.Range(-30.0f, 30.0f), UnityEngine.Random.Range(-30.0f, 30.0f), UnityEngine.Random.Range(-30.0f, 30.0f)) * pull; pull.y += 0.3f; leaf.Body.AddForce(pull * RakeFlyForce, ForceMode.Impulse); } else { - } } } public GameObject PilePrefab; - private void CheckPile() + public float PileSearchRadius = 0.7f; + + private List potentialPile = new List(); + private void MakePile() { - + anim.SetState("Stand", anim.Dir, 0); + potentialPile.Clear(); + foreach (Collider c in Physics.OverlapSphere(transform.position + rakeDir * RakeReachDist, PileSearchRadius, leafLayer)) + { + LeafPhysics leaf = c.GetComponentInParent(); + if (leaf != null) + { + potentialPile.Add(leaf); + } + } + + } private void FinishedRake() { state = State.Walking; - anim.SetState("Stand", anim.Dir, anim.Frame); + anim.SetState("Stand", anim.Dir, 0); } private void UpdateRakeBack(float val) diff --git a/FallUnity/Assets/PlayerInput/InputSource.cs b/FallUnity/Assets/PlayerInput/InputSource.cs index 2cccceb..8cf23ec 100644 --- a/FallUnity/Assets/PlayerInput/InputSource.cs +++ b/FallUnity/Assets/PlayerInput/InputSource.cs @@ -12,6 +12,9 @@ { MenuSelect, MenuCancel, + + MakePile, + DestroyPile } public enum InputAxis diff --git a/FallUnity/Assets/PlayerInput/KeyboardMouseInputSource.cs b/FallUnity/Assets/PlayerInput/KeyboardMouseInputSource.cs index fc97956..9ea58d2 100644 --- a/FallUnity/Assets/PlayerInput/KeyboardMouseInputSource.cs +++ b/FallUnity/Assets/PlayerInput/KeyboardMouseInputSource.cs @@ -41,7 +41,8 @@ { InputButton.MenuSelect, KeyCode.Return }, { InputButton.MenuCancel, KeyCode.Escape }, - //{ InputButton.UseItem, KeyCode.Space }, + { InputButton.MakePile, KeyCode.Space }, + { InputButton.DestroyPile, KeyCode.Backspace }, //{ InputButton.PickA, KeyCode.Q }, //{ InputButton.PickB, KeyCode.E }, diff --git a/FallUnity/Assets/PlayerInput/XboxControllerInputSource.cs b/FallUnity/Assets/PlayerInput/XboxControllerInputSource.cs index 1106813..d82bfcd 100644 --- a/FallUnity/Assets/PlayerInput/XboxControllerInputSource.cs +++ b/FallUnity/Assets/PlayerInput/XboxControllerInputSource.cs @@ -37,7 +37,8 @@ { InputButton.MenuSelect, XboxButton.A }, { InputButton.MenuCancel, XboxButton.B }, - //{ InputButton.UseItem, XboxButton.A }, + { InputButton.MakePile, XboxButton.A }, + { InputButton.DestroyPile, XboxButton.B }, //{ InputButton.PickA, XboxButton.LeftBumper }, //{ InputButton.PickB, XboxButton.RightBumper }, diff --git a/FallUnity/Assets/level.unity b/FallUnity/Assets/level.unity index ffb84bb..377f42e 100755 --- a/FallUnity/Assets/level.unity +++ b/FallUnity/Assets/level.unity @@ -2509,7 +2509,7 @@ m_Script: {fileID: 11500000, guid: 540cb6c0be5490d4687e3eb9c06ab209, type: 3} m_Name: m_EditorClassIdentifier: - Radius: 6.5 + Radius: 11.19 Rate: 7.33 Leafs: - {fileID: 114579094665962866, guid: 1701be1f15e160d4d904862548ae69de, type: 2} @@ -2740,7 +2740,8 @@ m_Script: {fileID: 11500000, guid: 7c526b2c54a6cc841aca85a6cf4cca83, type: 3} m_Name: m_EditorClassIdentifier: - MaxLeaves: 1200 + NumLeaves: 0 + MaxLeaves: 600 --- !u!4 &1421785357 Transform: m_ObjectHideFlags: 0 @@ -3679,6 +3680,11 @@ m_Modification: m_TransformParent: {fileID: 0} m_Modifications: + - target: {fileID: 114770286734950254, guid: 9f3dd22cf8fe21a43a067ab4b4ab708f, + type: 2} + propertyPath: LeafsForPile.Array.size + value: 3 + objectReference: {fileID: 0} - target: {fileID: 4968172230546488, guid: 9f3dd22cf8fe21a43a067ab4b4ab708f, type: 2} propertyPath: m_LocalPosition.x value: -2.09 @@ -3713,14 +3719,18 @@ objectReference: {fileID: 0} - target: {fileID: 114770286734950254, guid: 9f3dd22cf8fe21a43a067ab4b4ab708f, type: 2} - propertyPath: PilePrefab - value: - objectReference: {fileID: 1430576817403556, guid: d6cf61ddfecafa14991e99ec6f1e33f0, - type: 2} + propertyPath: LeafsForPile.Array.data[0] + value: 10 + objectReference: {fileID: 0} - target: {fileID: 114770286734950254, guid: 9f3dd22cf8fe21a43a067ab4b4ab708f, type: 2} - propertyPath: RakeFlyForce - value: 33 + propertyPath: LeafsForPile.Array.data[1] + value: 20 + objectReference: {fileID: 0} + - target: {fileID: 114770286734950254, guid: 9f3dd22cf8fe21a43a067ab4b4ab708f, + type: 2} + propertyPath: LeafsForPile.Array.data[2] + value: 40 objectReference: {fileID: 0} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: 9f3dd22cf8fe21a43a067ab4b4ab708f, type: 2}