Figured out solution to respawning bug

This commit is contained in:
Gregory Campbell
2020-01-11 13:35:50 -05:00
parent 15521e4a4c
commit 406a39655d
2 changed files with 32 additions and 14 deletions
+10 -4
View File
@@ -42,9 +42,11 @@ public class PlayerController : MonoBehaviour
float slideTime = 0.0f; float slideTime = 0.0f;
float wallRunTime = 0.0f; float wallRunTime = 0.0f;
float respawnTime = 1.0f;
float oneSec = 1.0f; float oneSec = 1.0f;
float halfSec = 0.5f; float halfSec = 0.5f;
float quarterSec = 0.25f; float quarterSec = 0.25f;
float tenthSec = 0.1f;
void Start() void Start()
{ {
@@ -70,13 +72,13 @@ public class PlayerController : MonoBehaviour
{ {
velocity = new Vector3(0,0,0); velocity = new Vector3(0,0,0);
//moveDirection = 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; finished = true;
} respawnTime = Time.time;
} else {
finished = false;
} }
} }
@@ -212,6 +214,7 @@ public class PlayerController : MonoBehaviour
if (characterController.collisionFlags == CollisionFlags.None) if (characterController.collisionFlags == CollisionFlags.None)
{ {
wallRunning = false; wallRunning = false;
//finished = false;
wall = 0; wall = 0;
} }
@@ -276,7 +279,10 @@ public class PlayerController : MonoBehaviour
Debug.Log("Current Position: " + transform.position); Debug.Log("Current Position: " + transform.position);
// Move the controller // Move the controller
if(finished == false && respawnTime + tenthSec < Time.time)
{
characterController.Move(velocity * Time.deltaTime); characterController.Move(velocity * Time.deltaTime);
}
//Move the player in different directions based on camera look direction //Move the player in different directions based on camera look direction
if(Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0) if(Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
+19 -7
View File
@@ -12,6 +12,7 @@ public class ProceduralGeneration : MonoBehaviour
public PlayerController script; public PlayerController script;
public GameObject[] obstacleList; public GameObject[] obstacleList;
private bool worldBuild = false;
private int selection = 0; private int selection = 0;
// Start is called before the first frame update // Start is called before the first frame update
@@ -20,6 +21,7 @@ public class ProceduralGeneration : MonoBehaviour
script = player.GetComponent<PlayerController>(); script = player.GetComponent<PlayerController>();
escalation = 1; escalation = 1;
worldBuild = false;
script.finished = false; script.finished = false;
script.transform.position = 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); script.transform.Rotate(0.0f, 0.0f, 0.0f, Space.Self);
@@ -34,21 +36,31 @@ public class ProceduralGeneration : MonoBehaviour
if(script.finished == true) if(script.finished == true)
{ {
respawn();
escalation++; escalation++;
levelBuild();
} }
if(worldBuild == true)
{
levelBuild();
}
}
void respawn()
{
Debug.Log("Sent: " + new Vector3((50*escalation)+100, 2, (50*escalation)+100));
script.transform.position = new Vector3((50*escalation)+100, 10, (50*escalation)+100);
script.transform.Rotate(0.0f, 0.0f, 0.0f, Space.Self);
worldBuild = true;
} }
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);
@@ -79,8 +91,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);
worldBuild = false;
script.finished = false; script.finished = false;
} }
} }