|
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: Health script: Do I have to write health = maxHealth;? I saw the 3rd person tutorial and didn't get why they did that.. Thank you :)
(comments are locked)
|
|
Which camera script are you using? If it's some camera following script like MouseOrbit.js, you must set the variable target to the player transform when respawning. Supposing it's MouseOrbit.js, you should add this script to your player prefab:
function Start(){
var camScript: MouseOrbit = Camera.main.GetComponent(MouseOrbit);
camScript.target = transform; // set variable target to the player transform
}
If your camera uses another script, replace MouseOrbit above with the script's name without quotes or extension (it's the script type). If you're using other kind of camera script which doesn't have the target variable, let me know. EDITED: God, I must be blind: the problem is in your script, in the function Again. You don't destroy your player, just teleport it to the respawn point. Tell me: do you use a first person style camera during the game? And during respawning, what do you want to do? Hide the player, move the camera to the respawn point, wait 1.6 seconds, then show the player and special effects, right? And what after? Return the camera to the first person style? If that's the idea, you should save the camera's local position, set the new local position relative to the player, move the player, do the respawning effect, then restore the local position. That's how the function should be:
function Again()
{
if (otherScript.lives>0){ // <- this bracket was missing!
var camTr = Camera.main.transform; // let's cache the cam transf
var camPos = camTr.localPosition; // save cam local pos
respawnPosition = Respawn.currentRespawn.transform.position;
// places the camera 4 units behind and 1 unit above player
camTr.localPosition += Vector3.up - 4 * Vector3.forward;
SendMessage("HidePlayer");
// teleports the player to 1 unit above respawnPosition
transform.position = respawnPosition + Vector3.up;
yield WaitForSeconds(1.6); // a little suspense
SendMessage("ShowPlayer"); // the player is back!
Respawn.currentRespawn.FireEffect ();
yield WaitForSeconds(0.5); // watch the effects for a while
camTr.localPosition = camPos; // restore cam local pos
} // close the if bracket
}
Okay I have added MouseOrbit to the main camera and the above script to the player. But the camera is really far from the player. I tried to change the above script to MouseLook but after respawning, I only could control the camera and it didn't follow the player. The MouseLook script doesn't have a target variable.
Aug 02 '11 at 02:50 AM
RamboPanda
I managed to reduce the distance by changing the distance in the MouseOrbit script to 0 but is it possible to shift it to eye level? It seems to work fine now except that I need to shift it up. I tried to manually place it at eye level but when I test it out the camera will move down to the belly area and the controls got out of control (left became right, going forward became going backward)... What should I do? Thank you for your help. :)
Aug 02 '11 at 03:40 AM
RamboPanda
How the camera was set in your previous version? Usually the Main Camera is a Player's child, so it goes everywhere the player goes - and if the player dies, it respawns with a new camera, since the camera is part of the player prefab. Did you use the standard First Person Controller from Standard Assets?
Aug 02 '11 at 01:42 PM
aldonaletto
Hello. Oh I see... Yes I'm using the standard first person controller from the standard assets. All I did was changed the name to Player.
Aug 03 '11 at 04:55 AM
RamboPanda
The First Person Controller comes with the camera childed to it. I suspect you've screwed your player prefab somehow, and that's why the player respawns with the camera at strange positions - it also explains why your character reborns with height 4 (this may have been changed by mistake in the current player prefab).
Aug 03 '11 at 06:11 AM
aldonaletto
(comments are locked)
|
|
Hey there (-; try this Java Script var maximumHitPoints = 100.0; var hitPoints = 100.0; var bulletGUI : GUIText; var rocketGUI : DrawRockets; var healthGUI : GUITexture; var walkSounds : AudioClip[]; var painLittle : AudioClip; var painBig : AudioClip; var die : AudioClip; var audioStepLength = 0.3; private var machineGun : MachineGun; private var rocketLauncher : RocketLauncher; private var healthGUIWidth = 0.0; private var gotHitTimer = -1.0; var rocketTextures : Texture[]; function Awake () { machineGun = GetComponentInChildren(MachineGun); rocketLauncher = GetComponentInChildren(RocketLauncher); } function ApplyDamage (damage : float) { if (hitPoints < 0.0) return; } function Die () { if (die) AudioSource.PlayClipAtPoint(die, transform.position); } function LateUpdate () { // Update gui every frame // We do this in late update to make sure machine guns etc. were already executed UpdateGUI(); } function PlayStepSounds () { var controller : CharacterController = GetComponent(CharacterController); } function UpdateGUI () { // Update health gui // The health gui is rendered using a overlay texture which is scaled down based on health // - Calculate fraction of how much health we have left (0...1) var healthFraction = Mathf.Clamp01(hitPoints / maximumHitPoints); }
(comments are locked)
|
