From 559faba7b9ae1d5ee09804e3f8ba815c40370366 Mon Sep 17 00:00:00 2001 From: haitem Date: Sun, 30 Jan 2022 12:15:49 +0100 Subject: [PATCH] Commit fix --- .../Prefabs/Platforms/platform_neutral.prefab | 2 +- .../Platforms/platform_neutral_sharp.prefab | 2 +- .../Prefabs/Platforms/platform_power.prefab | 2 +- .../Prefabs/Platforms/platform_rrange.prefab | 2 +- .../Prefabs/Platforms/platform_speed.prefab | 2 +- .../Prefabs/Platforms/platform_start.prefab | 2 +- Assets/Prefabs/Player.prefab | 6 +- Assets/Prefabs/platforms/Platform_Blue.prefab | 4 +- .../Prefabs/platforms/Platform_Green.prefab | 4 +- Assets/Prefabs/platforms/Platform_Red.prefab | 4 +- .../Prefabs/platforms/Platform_yellow.prefab | 4 +- Assets/Scripts/PlayerController.cs | 58 +++++++------------ 12 files changed, 39 insertions(+), 53 deletions(-) diff --git a/Assets/Prefabs/Platforms/platform_neutral.prefab b/Assets/Prefabs/Platforms/platform_neutral.prefab index 293d6b8..4091fd4 100644 --- a/Assets/Prefabs/Platforms/platform_neutral.prefab +++ b/Assets/Prefabs/Platforms/platform_neutral.prefab @@ -247,4 +247,4 @@ Rigidbody: m_IsKinematic: 0 m_Interpolate: 0 m_Constraints: 126 - m_CollisionDetection: 2 + m_CollisionDetection: 1 diff --git a/Assets/Prefabs/Platforms/platform_neutral_sharp.prefab b/Assets/Prefabs/Platforms/platform_neutral_sharp.prefab index 6c5c45c..e132eb7 100644 --- a/Assets/Prefabs/Platforms/platform_neutral_sharp.prefab +++ b/Assets/Prefabs/Platforms/platform_neutral_sharp.prefab @@ -177,7 +177,7 @@ Rigidbody: m_IsKinematic: 0 m_Interpolate: 0 m_Constraints: 126 - m_CollisionDetection: 2 + m_CollisionDetection: 1 --- !u!1 &1560962679917322222 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/Platforms/platform_power.prefab b/Assets/Prefabs/Platforms/platform_power.prefab index 7b8e27f..8e7d316 100644 --- a/Assets/Prefabs/Platforms/platform_power.prefab +++ b/Assets/Prefabs/Platforms/platform_power.prefab @@ -227,4 +227,4 @@ Rigidbody: m_IsKinematic: 0 m_Interpolate: 0 m_Constraints: 126 - m_CollisionDetection: 2 + m_CollisionDetection: 1 diff --git a/Assets/Prefabs/Platforms/platform_rrange.prefab b/Assets/Prefabs/Platforms/platform_rrange.prefab index 9659e34..c79c161 100644 --- a/Assets/Prefabs/Platforms/platform_rrange.prefab +++ b/Assets/Prefabs/Platforms/platform_rrange.prefab @@ -345,4 +345,4 @@ Rigidbody: m_IsKinematic: 0 m_Interpolate: 0 m_Constraints: 126 - m_CollisionDetection: 2 + m_CollisionDetection: 1 diff --git a/Assets/Prefabs/Platforms/platform_speed.prefab b/Assets/Prefabs/Platforms/platform_speed.prefab index ff241a8..fda805a 100644 --- a/Assets/Prefabs/Platforms/platform_speed.prefab +++ b/Assets/Prefabs/Platforms/platform_speed.prefab @@ -164,7 +164,7 @@ Rigidbody: m_IsKinematic: 0 m_Interpolate: 0 m_Constraints: 126 - m_CollisionDetection: 2 + m_CollisionDetection: 1 --- !u!1 &8214805574275809151 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/Platforms/platform_start.prefab b/Assets/Prefabs/Platforms/platform_start.prefab index c0dd0b6..6b4caa1 100644 --- a/Assets/Prefabs/Platforms/platform_start.prefab +++ b/Assets/Prefabs/Platforms/platform_start.prefab @@ -294,4 +294,4 @@ Rigidbody: m_IsKinematic: 0 m_Interpolate: 0 m_Constraints: 126 - m_CollisionDetection: 2 + m_CollisionDetection: 1 diff --git a/Assets/Prefabs/Player.prefab b/Assets/Prefabs/Player.prefab index cb7f149..b72c883 100644 --- a/Assets/Prefabs/Player.prefab +++ b/Assets/Prefabs/Player.prefab @@ -1604,7 +1604,7 @@ Rigidbody: m_AngularDrag: 0.05 m_UseGravity: 1 m_IsKinematic: 0 - m_Interpolate: 2 + m_Interpolate: 0 m_Constraints: 112 m_CollisionDetection: 2 --- !u!114 &3244356566819001086 @@ -2072,7 +2072,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3244356567913423209} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0.55, z: -0.877} + m_LocalPosition: {x: 0, y: 0.55, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] @@ -2102,7 +2102,7 @@ Camera: y: 0 width: 1 height: 1 - near clip plane: 0.3 + near clip plane: 0.1 far clip plane: 1000 field of view: 60 orthographic: 0 diff --git a/Assets/Prefabs/platforms/Platform_Blue.prefab b/Assets/Prefabs/platforms/Platform_Blue.prefab index cb79eef..e920240 100644 --- a/Assets/Prefabs/platforms/Platform_Blue.prefab +++ b/Assets/Prefabs/platforms/Platform_Blue.prefab @@ -101,7 +101,7 @@ GameObject: - component: {fileID: 2527761051471871889} - component: {fileID: 4240483973579556787} m_Layer: 0 - m_Name: platform_blue + m_Name: Platform_Blue m_TagString: platform m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -344,4 +344,4 @@ Rigidbody: m_IsKinematic: 0 m_Interpolate: 0 m_Constraints: 126 - m_CollisionDetection: 2 + m_CollisionDetection: 1 diff --git a/Assets/Prefabs/platforms/Platform_Green.prefab b/Assets/Prefabs/platforms/Platform_Green.prefab index 24c9161..9d03f66 100644 --- a/Assets/Prefabs/platforms/Platform_Green.prefab +++ b/Assets/Prefabs/platforms/Platform_Green.prefab @@ -116,7 +116,7 @@ GameObject: - component: {fileID: -7597049073915248875} - component: {fileID: 3278078638141404736} m_Layer: 0 - m_Name: platform_green + m_Name: Platform_Green m_TagString: platform m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -245,7 +245,7 @@ Rigidbody: m_IsKinematic: 0 m_Interpolate: 0 m_Constraints: 126 - m_CollisionDetection: 2 + m_CollisionDetection: 1 --- !u!1 &8985668614484660023 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/platforms/Platform_Red.prefab b/Assets/Prefabs/platforms/Platform_Red.prefab index b35bccc..85210fd 100644 --- a/Assets/Prefabs/platforms/Platform_Red.prefab +++ b/Assets/Prefabs/platforms/Platform_Red.prefab @@ -117,7 +117,7 @@ GameObject: - component: {fileID: 5862113707430629064} - component: {fileID: -6889792310482815023} m_Layer: 0 - m_Name: platform_red + m_Name: Platform_Red m_TagString: platform m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -344,4 +344,4 @@ Rigidbody: m_IsKinematic: 0 m_Interpolate: 0 m_Constraints: 126 - m_CollisionDetection: 2 + m_CollisionDetection: 1 diff --git a/Assets/Prefabs/platforms/Platform_yellow.prefab b/Assets/Prefabs/platforms/Platform_yellow.prefab index 817a106..c108c5e 100644 --- a/Assets/Prefabs/platforms/Platform_yellow.prefab +++ b/Assets/Prefabs/platforms/Platform_yellow.prefab @@ -117,7 +117,7 @@ GameObject: - component: {fileID: 8383421295717427161} - component: {fileID: 3996111038030861644} m_Layer: 0 - m_Name: platform_yellow + m_Name: Platform_yellow m_TagString: platform m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -345,4 +345,4 @@ Rigidbody: m_IsKinematic: 0 m_Interpolate: 0 m_Constraints: 126 - m_CollisionDetection: 2 + m_CollisionDetection: 1 diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index 153d760..915a6bb 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -71,7 +71,7 @@ public class PlayerController : MonoBehaviour isRunning = Input.GetKey(KeyCode.LeftShift); if (canMove && currentSpeed < minSpeed) { - currentSpeed += 0.0005f; + currentSpeed += 0.005f; } if (Input.GetAxis("Vertical") > 0 && currentSpeed < maxSpeed) @@ -147,7 +147,7 @@ public class PlayerController : MonoBehaviour inAir = false; } - if (rb.velocity.magnitude != 0 && Vector3.Dot(rb.velocity.normalized, Physics.gravity.normalized) > 0) + if (Vector3.Distance(transform.position, new Vector3(0f,0f, transform.position.z)) > 10f) { // Debug.Log("Player is falling :)"); this.isFalling = true; @@ -167,33 +167,6 @@ public class PlayerController : MonoBehaviour transform.RotateAround(axis, angle * Time.deltaTime * 8f); } - if (pullObject != null) - { - PlatformManager platform = pullObject.GetComponent(); - if (platform != null) - { - float step = platform.speed * Time.deltaTime * 10f; - rb.AddForce((pullObject.transform.position - transform.position) * step, ForceMode.Force); - } - if (Vector3.Distance(pullObject.transform.position, transform.position) > 5f) - { - pullObject = null; - } - } - - if (pushObject != null) - { - PlatformManager platform = pushObject.GetComponent(); - if (platform != null) - { - float step = platform.speed * Time.deltaTime * 10f; - rb.AddForce(-(pushObject.transform.position - transform.position) * step, ForceMode.Force); - } - if (Vector3.Distance(pushObject.transform.position, transform.position) > 5f) - { - pushObject = null; - } - } var distanceFromYAxis = new Vector2(rb.position.x, rb.position.y).magnitude; if (distanceFromYAxis > this.maxDistanceFromCenterLine) { @@ -210,6 +183,23 @@ public class PlayerController : MonoBehaviour if (other.gameObject.tag == "platform") { Physics.gravity = this.downDirection * 9.81f; + + PlatformManager platform = pullObject.GetComponent(); + + if (platform != null) + { + platform.Step(); + float step = platform.speed * Time.deltaTime * 10f; + switch (platform.type) + { + case PlatformManager.PlatformType.Push: + rb.AddForce(-(pushObject.transform.position - transform.position) * step, ForceMode.Force); + break; + case PlatformManager.PlatformType.Pull: + rb.AddForce((other.transform.position - transform.position) * step, ForceMode.Force); + break; + } + } } } @@ -254,12 +244,8 @@ public class PlayerController : MonoBehaviour switch (platform.type) { case PlatformManager.PlatformType.Push: - pushObject = other.gameObject; - pullObject = null; break; case PlatformManager.PlatformType.Pull: - pullObject = other.gameObject; - pushObject = null; break; case PlatformManager.PlatformType.RotateY: break; @@ -291,11 +277,11 @@ public class PlayerController : MonoBehaviour return; } - Vector3 gDirection = -other.GetContact(0).normal; - saveDirection = gDirection; + Vector3 gDirection = -transform.up; + saveDirection = -other.GetContact(0).normal; if (platform == null) { - gDirection = -other.GetContact(0).normal; + gDirection = -transform.up; } platformForward = other.transform.forward; platformRight = other.transform.right;