diff --git a/Assets/Scenes/Vasek.unity b/Assets/Scenes/Vasek.unity index 19e374c..3285f3d 100644 --- a/Assets/Scenes/Vasek.unity +++ b/Assets/Scenes/Vasek.unity @@ -382,6 +382,14 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 0} m_Modifications: + - target: {fileID: 3244356566819001086, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} + propertyPath: distanceFromYAxis + value: 30 + objectReference: {fileID: 0} + - target: {fileID: 3244356566819001086, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} + propertyPath: maxDistanceFromCenterLine + value: 30 + objectReference: {fileID: 0} - target: {fileID: 3244356567786994344, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} propertyPath: m_Name value: Player diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index 63fa796..a87fc7d 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -4,6 +4,7 @@ using UnityEngine; public class PlayerController : MonoBehaviour { + public float maxDistanceFromCenterLine; [Header("Move")] public float speed = 7.5f; public float maxSpeed = 15.0f; @@ -113,9 +114,9 @@ public class PlayerController : MonoBehaviour jump = false; } - if(rb.velocity.magnitude != 0 && Vector3.Dot(rb.velocity.normalized, Physics.gravity.normalized) > 0 ) + if (rb.velocity.magnitude != 0 && Vector3.Dot(rb.velocity.normalized, Physics.gravity.normalized) > 0) { - Debug.Log("Player is falling :)"); + // Debug.Log("Player is falling :)"); this.isFalling = true; } else @@ -136,7 +137,8 @@ public class PlayerController : MonoBehaviour if (pullObject != null) { PlatformManager platform = pullObject.GetComponent(); - if (platform != null) { + if (platform != null) + { float step = platform.speed * Time.deltaTime * 10f; rb.AddForce((pullObject.transform.position - transform.position) * step, ForceMode.Force); } @@ -159,6 +161,15 @@ public class PlayerController : MonoBehaviour pushObject = null; } } + var distanceFromYAxis = new Vector2(rb.position.x, rb.position.y).magnitude; + if (distanceFromYAxis > maxDistanceFromCenterLine) + { + Debug.Log("Player fell out of map."); + rb.velocity = Vector3.zero; + Physics.gravity = -Vector3.up * 9.81f; + + UnityEngine.SceneManagement.SceneManager.LoadScene(0); + } } void OnCollisionExit(Collision other) @@ -219,7 +230,8 @@ public class PlayerController : MonoBehaviour Vector3 gDirection = -other.GetContact(0).normal; PlatformManager platform = other.gameObject.GetComponent(); - if (platform != null) { + if (platform != null) + { switch (platform.type) { case PlatformManager.PlatformType.Push: