Hello! Whenever my player respawns, my camera does not follow the player. I’m using a first person controller and the more I respawn, the further my camera is from my player and it became very hard to control… What my script does is when my player hit into some obstacles called “Crash” the life will decrease by 1 and automatically respawn. If lives = 0, level “GameOver” loads. This script is linked to my health script. Also why is it that the height of my character controller always increase to 4? Please advise. Thank you
Damage script:
var otherScript : Health;
var nextActivationTime = 0.0;
var applyDamageDuration = 4;
var deathSound : UnityEngine.AudioClip;
private var timer = 0.0;
private var levelStateMachine : LevelStatus;
function OnControllerColliderHit (collisionObject: ControllerColliderHit)
{
if(collisionObject.gameObject.name == "Crash" && Time.time > nextActivationTime)
{
nextActivationTime = Time.time + applyDamageDuration;
otherScript.lives--;
yield WaitForSeconds(3);
Again();
if(otherScript.lives <= 0)
Die();
}
}
function Again()
{
if (otherScript.lives>0)
respawnPosition = Respawn.currentRespawn.transform.position;
Camera.main.transform.position = respawnPosition - (transform.forward * 4) + Vector3.up;
SendMessage("HidePlayer");
transform.position = respawnPosition + Vector3.up;
yield WaitForSeconds(1.6);
SendMessage("ShowPlayer");
Respawn.currentRespawn.FireEffect ();
}
function Die()
{
if (deathSound)
{
AudioSource.PlayClipAtPoint(deathSound, transform.position);
}
Application.LoadLevel("GameOver");
}
Health script:
var lives = 3;
var speedBoostDuration = 4;
var nextActivationTime = 0.0;
private var timer = 0.0;
function OnControllerColliderHit (collisionObject: ControllerColliderHit)
{
if(collisionObject.gameObject.name == "Heart" && Time.time > nextActivationTime)
{
nextActivationTime = Time.time + speedBoostDuration;
Destroy(collisionObject.gameObject);
if (lives == 3)
lives += 0;
else
lives++;
if(lives <=0)
Application.LoadLevel("GameOver");
yield WaitForSeconds(3);
}
}
Do I have to write health = maxHealth;? I saw the 3rd person tutorial and didn’t get why they did that… Thank you