- Home /
Why does my character pass through walls when he respawns and I lose control of him?
I am working on a 2d platformer and when I respawn my character falls and passes through everything. This is my respawn script private void Awake() { instance = this; } public void Respawn () { Instantiate(Chip, respawnPoint.position, Quaternion.identity); } }  
Answer by Whitewalkergp · Mar 04 at 01:50 PM
hey , maybe the character that gets instantiated does not have any of your components attached to it ? have you checked that? and also maybe make a prefab of your character and try to instantiate the prefab.
I also recommend instead of instantiating the character you could deactivate the character using gameobject.setactive(false) and then change it's position to the respawn position and then active the character using gameobject.setactive(true);
Answer by unity_580000564 · Mar 06 at 08:06 PM
It has the components all on it which is what confuses me and my character is a prefab
I tried making it but now it just gets rid of the guy and I got rid of the destroy character
    Death:
  private void OnCollisionEnter2D(Collision2D collision) {
     if (collision.gameObject.CompareTag("Spikes")){
         LevelManager.instance.Respawn();
 }
     }
 
 Respawn:
 public void Respawn () {
      gameObject.SetActive(false);
      transform.position = new Vector3(44.5f,19.3f,-0.9598976f);
      gameObject.SetActive(true);
      
  }
 
 
attach this component to your Player
 public class Death : MonoBehaviour
 {
     public Vector3 RespawnPos;
     private void OnTriggerEnter2D(Collider2D collision)
     {
         if(collision.CompareTag("Spikes"))
         {
             Respawn();
         }
     }
     public void Respawn()
     {
         Color c = new Color(0, 0, 0, 0);
         gameObject.GetComponent<SpriteRenderer>().color = c;
         //you can acc delay or animation here
         transform.position = RespawnPos;
         c = new Color(1, 1, 1, 1);
         gameObject.GetComponent<SpriteRenderer>().color = c;
     }
 }
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                