diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index b8188602c..66b550c74 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -542,7 +542,11 @@ PrefabInstance: m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] - m_AddedComponents: [] + m_AddedComponents: + - targetCorrespondingSourceObject: {fileID: 3947371150140413365, guid: 73a3583486de62c4a82ee0734c80f1bf, + type: 3} + insertIndex: -1 + addedObject: {fileID: 1135435428} m_SourcePrefab: {fileID: 100100000, guid: 73a3583486de62c4a82ee0734c80f1bf, type: 3} --- !u!1001 &392614949 PrefabInstance: @@ -1035,6 +1039,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: f4422e4ad9a4faf409cd394f7efaec2a, type: 3} m_Name: m_EditorClassIdentifier: + jumpForce: 10 horizontalInput: {fileID: 11400000, guid: 93242d5c5434ab44c966480e1ff5c8d5, type: 2} verticalInput: {fileID: 11400000, guid: 22faa7b25fade4845812eab67089a12b, type: 2} upDownInput: {fileID: 11400000, guid: 3ff45f65e26c59542a8e4f3772860382, type: 2} @@ -1703,6 +1708,33 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 939202851} m_CullTransparentMesh: 1 +--- !u!1 &1135435423 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 3947371150140413365, guid: 73a3583486de62c4a82ee0734c80f1bf, + type: 3} + m_PrefabInstance: {fileID: 333242158} + m_PrefabAsset: {fileID: 0} +--- !u!65 &1135435428 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1135435423} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Size: {x: 10, y: 2.220446e-16, z: 10} + m_Center: {x: 0, y: 0, z: 0} --- !u!114 &1235137767 stripped MonoBehaviour: m_CorrespondingSourceObject: {fileID: 1748615501916967598, guid: 0d52ffd9c87ab484b88610c4acf5db24, @@ -2502,22 +2534,22 @@ PrefabInstance: - target: {fileID: 3849934062868920522, guid: 5fbb7c7c8ec47e849afba1b658f3e07e, type: 3} propertyPath: m_LocalRotation.w - value: 0.19865541 + value: 0.19903675 objectReference: {fileID: 0} - target: {fileID: 3849934062868920522, guid: 5fbb7c7c8ec47e849afba1b658f3e07e, type: 3} propertyPath: m_LocalRotation.x - value: 0.082976505 + value: 0.08316172 objectReference: {fileID: 0} - target: {fileID: 3849934062868920522, guid: 5fbb7c7c8ec47e849afba1b658f3e07e, type: 3} propertyPath: m_LocalRotation.y - value: 0.9011034 + value: 0.9009754 objectReference: {fileID: 0} - target: {fileID: 3849934062868920522, guid: 5fbb7c7c8ec47e849afba1b658f3e07e, type: 3} propertyPath: m_LocalRotation.z - value: -0.37638244 + value: -0.37644637 objectReference: {fileID: 0} - target: {fileID: 3919916255551741050, guid: 5fbb7c7c8ec47e849afba1b658f3e07e, type: 3} diff --git a/Assets/Scripts/KerstSpecial/RaceController.cs b/Assets/Scripts/KerstSpecial/RaceController.cs index 860c258b1..c0a2268b7 100644 --- a/Assets/Scripts/KerstSpecial/RaceController.cs +++ b/Assets/Scripts/KerstSpecial/RaceController.cs @@ -45,15 +45,14 @@ public class RaceController : MonoBehaviour [SerializeField] private TextAsset routeFile; private List routeCoords = new List(); + private int currentCoordinateIndex = 0; - //53.198472, 5.791865 - private Coordinate coord = new Coordinate(CoordinateSystem.WGS84, 53.198472d, 5.791865d, 0); + private MeshCollider nothingMeshCollider; private void Start() { - freeCam = FindObjectOfType(); - cameraStartRotation = GetCameraStartRotation(); + freeCam = FindObjectOfType(); horizontalInput.AddListenerStarted(MoveHorizontally); verticalInput.AddListenerStarted(MoveForwardBackwards); @@ -62,6 +61,8 @@ private void Start() GetCoordinatesForRoute(); InitPlayer(); + + nothingMeshCollider = FindObjectOfType().gameObject.GetComponent(); } private void InitPlayer() @@ -93,6 +94,12 @@ private void Jump(bool jump) } } + private void OnCollisionEnter(Collision collision) + { + Debug.Log("HAVING COLLISION" + collision); + } + + private Vector3 floorPoint = Vector3.zero; private void FixedUpdate() { if (!isReadyToMove) @@ -107,10 +114,31 @@ private void FixedUpdate() } else { - Vector2 screenPoint = Camera.main.WorldToScreenPoint(player.transform.position + Vector3.down); //bottom of player - Vector3 floorPoint = raycaster.GetWorldPointAtCameraScreenPoint(Camera.main, new Vector3(screenPoint.x, screenPoint.y, 0)); + //Vector2 screenPoint = Camera.main.WorldToScreenPoint(player.transform.position + Vector3.down); //bottom of player + //Vector3 floorPoint = raycaster.GetWorldPointAtCameraScreenPoint(Camera.main, new Vector3(screenPoint.x, screenPoint.y, 0)); + RaycastHit[] hits = new RaycastHit[8]; + Physics.RaycastNonAlloc(playerRigidBody.transform.position + Vector3.up * 10, Vector3.down, hits); + int mcCount = 0; + float lowestMc = float.MaxValue; + for(int i = 0; i < hits.Length; i++) + { + if(hits[i].collider == null) continue; + + if (hits[i].collider is MeshCollider mc && hits[i].collider != nothingMeshCollider) + { + if (hits[i].point.y < lowestMc) + { + //if the next hitpoint is suddenly above the player and the difference is greater than 0.5f then skip this next hitpoint + if (hits[i].point.y > playerRigidBody.transform.position.y && Mathf.Abs(hits[i].point.y - playerRigidBody.transform.position.y) > 0.5f) + continue; + + lowestMc = hits[i].point.y; + floorPoint.y = lowestMc; + } + } + } float yDist = Mathf.Abs(floorPoint.y - player.transform.position.y); - floorPoint.y = -1; //ugly fix but better for now + //floorPoint.y = -1; //ugly fix but better for now bool isGrounded = yDist < 1f; Debug.Log("isgrounded:" + isGrounded); if(isGrounded) @@ -118,10 +146,11 @@ private void FixedUpdate() hasJumped = false; } - if (playerRigidBody.position.y < floorPoint.y) + if (playerRigidBody.position.y < floorPoint.y - 0.1f) { playerRigidBody.transform.SetPositionAndRotation(new Vector3(playerRigidBody.position.x, floorPoint.y, playerRigidBody.position.z), player.transform.rotation); } + Debug.Log("FLOORY" + floorPoint.y); //playerRigidBody.transform.SetPositionAndRotation(Vector3.Lerp(player.transform.position, new Vector3(player.transform.position.x, floorPoint.y, player.transform.position.z), Time.fixedDeltaTime * 3), player.transform.rotation); playerRigidBody.angularVelocity = Vector3.zero; } @@ -129,9 +158,21 @@ private void FixedUpdate() private void Update() { + CheckNextCoordinate(); + if (routeCoords == null) + return; + jumpTimer -= Time.deltaTime; - unityStartTarget = coord.ToUnity(); - unityStartTarget.y = camHeight; + + if(!isReadyForStart) + { + Coordinate nextCoord = new Coordinate(CoordinateSystem.WGS84, routeCoords[0].x, routeCoords[0].y, 0); + //nextCoord = new Coordinate(CoordinateSystem.WGS84, 53.198472d, 5.791865d, 0); + unityStartTarget = nextCoord.ToUnity(); + unityStartTarget.y = camHeight; + cameraStartRotation = GetCameraStartRotation(); + } + if ((Vector3.Distance(freeCam.transform.position, unityStartTarget) > 1 || Quaternion.Angle(freeCam.transform.rotation, cameraStartRotation) > 1) && !isReadyForStart) { freeCam.transform.position = Vector3.Lerp(freeCam.transform.position, unityStartTarget, Time.deltaTime * camLerpSpeed); @@ -172,6 +213,25 @@ private void Update() playerRigidBody.useGravity = isGrounded; } + private void CheckNextCoordinate() + { + if (currentCoordinateIndex >= routeCoords.Count) + { + //FINISH + return; + } + + Coordinate nextCoord = new Coordinate(CoordinateSystem.WGS84, routeCoords[currentCoordinateIndex].x, routeCoords[currentCoordinateIndex].y, 0); + Vector3 unityCoord = nextCoord.ToUnity(); + float distance = Vector3.Distance(player.transform.position, unityCoord); + if(distance < 2) + { + currentCoordinateIndex++; + Debug.Log("WE HIT THE COORD" + currentCoordinateIndex); + } + } + + private Quaternion GetCameraStartRotation() { Quaternion freeCamRotation = freeCam.transform.rotation; @@ -276,18 +336,18 @@ private void GetCoordinatesForRoute() { routeCoords = ExtractLatLon(routeFile.text); - foreach(Vector2 c in routeCoords) - { - Coordinate coord = new Coordinate(CoordinateSystem.WGS84, c.x, c.y, 0); - GameObject routeObject = GameObject.CreatePrimitive(PrimitiveType.Cube); - routeObject.transform.localScale = Vector3.one * 5f; - WorldTransform wt = routeObject.AddComponent(); - GameObjectWorldTransformShifter shifter = routeObject.AddComponent(); - wt.SetShifter(shifter); - Vector3 unityCoord = coord.ToUnity(); - unityCoord.y = 2; - routeObject.transform.position = unityCoord; - } + //foreach(Vector2 c in routeCoords) + //{ + // Coordinate coord = new Coordinate(CoordinateSystem.WGS84, c.x, c.y, 0); + // GameObject routeObject = GameObject.CreatePrimitive(PrimitiveType.Cube); + // routeObject.transform.localScale = Vector3.one * 5f; + // WorldTransform wt = routeObject.AddComponent(); + // GameObjectWorldTransformShifter shifter = routeObject.AddComponent(); + // wt.SetShifter(shifter); + // Vector3 unityCoord = coord.ToUnity(); + // unityCoord.y = 2; + // routeObject.transform.position = unityCoord; + //} } else {