Added the resetting of a level after player reaches the end, encountered strange bug that causes player to not teleport back to start

This commit is contained in:
Gregory Campbell
2020-01-11 00:46:40 -05:00
parent e801bfe945
commit 15521e4a4c
3 changed files with 24 additions and 15 deletions
+1 -1
View File
@@ -606,7 +606,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 7e52a505534642144b4f939196badbab, type: 3} m_Script: {fileID: 11500000, guid: 7e52a505534642144b4f939196badbab, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
escalation: 1 escalation: 0
player: {fileID: 1644583839} player: {fileID: 1644583839}
script: {fileID: 1644583840} script: {fileID: 1644583840}
obstacleList: obstacleList:
+9 -3
View File
@@ -68,9 +68,15 @@ public class PlayerController : MonoBehaviour
if(hit.gameObject.tag == "Finish") if(hit.gameObject.tag == "Finish")
{ {
finished = true;
velocity = new Vector3(0,0,0); velocity = new Vector3(0,0,0);
//moveDirection = new Vector3(0,0,0);
maxSpeed = 0; maxSpeed = 0;
if((Input.GetAxis("Horizontal") == 0 && Input.GetAxis("Vertical") == 0) || Input.GetButton("Stop"))
{
finished = true;
}
} }
} }
@@ -261,14 +267,14 @@ public class PlayerController : MonoBehaviour
velocity.y = moveDirection.y; velocity.y = moveDirection.y;
Debug.Log(moveDirection.y+"\n");
if(moveDirection.y <= -5 && Mathf.Abs(velocity.x) <= 1.5f && Mathf.Abs(velocity.z) <= 1.5f) if(moveDirection.y <= -5 && Mathf.Abs(velocity.x) <= 1.5f && Mathf.Abs(velocity.z) <= 1.5f)
{ {
velocity.x = velocity.x * Mathf.Abs(moveDirection.y); velocity.x = velocity.x * Mathf.Abs(moveDirection.y);
velocity.z = velocity.z * Mathf.Abs(moveDirection.y); velocity.z = velocity.z * Mathf.Abs(moveDirection.y);
} }
Debug.Log("Current Position: " + transform.position);
// Move the controller // Move the controller
characterController.Move(velocity * Time.deltaTime); characterController.Move(velocity * Time.deltaTime);
+12 -9
View File
@@ -21,6 +21,9 @@ public class ProceduralGeneration : MonoBehaviour
script = player.GetComponent<PlayerController>(); script = player.GetComponent<PlayerController>();
escalation = 1; escalation = 1;
script.finished = false; script.finished = false;
script.transform.position = new Vector3((50*escalation)+100, 2, (50*escalation)+100);
script.transform.Rotate(0.0f, 0.0f, 0.0f, Space.Self);
script.pivot.transform.Rotate(0.0f, 225.0f, 0.0f, Space.Self);
levelBuild(); levelBuild();
} }
@@ -32,7 +35,6 @@ public class ProceduralGeneration : MonoBehaviour
{ {
escalation++; escalation++;
levelBuild(); levelBuild();
} }
@@ -42,6 +44,11 @@ public class ProceduralGeneration : MonoBehaviour
void levelBuild() void levelBuild()
{ {
Debug.Log("Sent: " + new Vector3((50*escalation)+100, 2, (50*escalation)+100));
script.transform.position = new Vector3((50*escalation)+100, 2, (50*escalation)+100);
script.transform.Rotate(0.0f, 0.0f, 0.0f, Space.Self);
Debug.Log("Player: " + new Vector3((50*escalation)+100, 2, (50*escalation)+100));
GameObject[] oldObjects = GameObject.FindGameObjectsWithTag("Environment"); GameObject[] oldObjects = GameObject.FindGameObjectsWithTag("Environment");
foreach (GameObject target in oldObjects) { foreach (GameObject target in oldObjects) {
GameObject.Destroy(target); GameObject.Destroy(target);
@@ -62,6 +69,9 @@ public class ProceduralGeneration : MonoBehaviour
selection = Random.Range(2, obstacleList.Length); selection = Random.Range(2, obstacleList.Length);
Instantiate(obstacleList[selection], new Vector3(50*i, 5, -50*j), Quaternion.identity); Instantiate(obstacleList[selection], new Vector3(50*i, 5, -50*j), Quaternion.identity);
script.transform.position = new Vector3((50*escalation)+100, 2, (50*escalation)+100);
script.transform.Rotate(0.0f, 0.0f, 0.0f, Space.Self);
} }
} }
@@ -69,15 +79,8 @@ public class ProceduralGeneration : MonoBehaviour
Instantiate(obstacleList[0], new Vector3((50*escalation)+100, 0, (50*escalation)+100), Quaternion.identity); Instantiate(obstacleList[0], new Vector3((50*escalation)+100, 0, (50*escalation)+100), Quaternion.identity);
Instantiate(obstacleList[1], new Vector3(-((50*escalation)+100), 0, -((50*escalation)+100)), Quaternion.identity); Instantiate(obstacleList[1], new Vector3(-((50*escalation)+100), 0, -((50*escalation)+100)), Quaternion.identity);
player.transform.position = new Vector3((50*escalation)+100, 2, (50*escalation)+100);
player.transform.Rotate(0.0f, 225.0f, 0.0f, Space.Self);
if(escalation == 1)
{
script.pivot.transform.Rotate(0.0f, 225.0f, 0.0f, Space.Self);
}
script.finished = false; script.finished = false;
} }
} }