When my player respawns it starts to shake and twitch around for a second, and then goes back to normal. I don’t know why it does it. Here’s a poor quality video to show you.
Here’s some code
Script on the object that senses when to disable the Player.
#pragma strict
var Player : GameObject;
function Start () {
}
function Update () {
}
function OnCollisionEnter2D (col : Collision2D) {
if(col.gameObject.tag == "Floor"){
Debug.Log ("Kill");
Player.SetActive(false);
}
}
Script on the camera to enable (respawn) the character
#pragma strict
var Player : GameObject;
var Spawn : GameObject;
function IsHeDead(){
if(!Player.activeSelf){
yield WaitForSeconds(1);
Player.transform.position = Spawn.transform.position;
Player.SetActive(true);
}
}
function Start () {
}
function Update () {
IsHeDead();
}
So the problem is that it does that weird shake thing when it spawns back in. How do I make it not shake. Thanks.
If I should add any more detail or pictures please tell me to do so, and thank you.
The PC I’m on tonight is a piece of crap and wont let me view your video even though I installed adobe flash player 15,000 times… anyway… From what I can guess by your script : In Update you constantly call IsHeDead(), and if he is dead (not active) you wait for one second and then set him active. That means for one second, before he finally becomes active AND you move his position, ALL the frames that pass during Update during that second that call IsHeDead will also wait one second then change his position. So, if your spawnpoint isn’t exactly in just the right spot to where your player doesn’t drop/move away from that same exact position on respawn, then every one of those other calls to IsHeDead that happened in that first second will move him back to the spawn position, then he’ll drop/move again, then move back, and so-on… you need to make IsHeDead only run ONCE. Easy way to do it is using a good-ol’ boolean.
eg :
private var isRespawning = false ;
function IsHeDead()
{
if(!Player.activeSelf && !isRespawning)
{
isRespawning = true ;
//yield awhile ;
//do some stuff ;
isRespawning = false ;
}
}