Why does instantiating a prefab break the original's behaviour

I am trying to create a simple version of Quidditch from Harry Potter. I’ve got two opposing teams, that try to touch the gold ball that flies randomly. When I have two game objects in the scene, they chase perfectly. However, when I then try to spawn more teammates, the previous player stops tracking the gold ball. I have been scouring the internet and I haven’t been able to figure this out. Please help me.

Here is the player script:

public class Gryffindor : MonoBehaviour {

	public static float maxVelocity = 16;
	public static float maxAcceleration = 20;
	public static double tacklingProb = 0.3;
	private static Rigidbody rb;
	private static GameObject snitch;
	private static GameObject[] enemy;
	private static GameObject[] team;


	// Use this for initialization
	void Start () {
		
		rb = GetComponent<Rigidbody> ();
		rb.useGravity = false;
		snitch = GameObject.FindGameObjectWithTag ("Snitch");
		enemy = GameObject.FindGameObjectsWithTag("S");
		team = GameObject.FindGameObjectsWithTag("G");

	}
	
	// Update is called once per frame
	void Update () {

		//transform.rotation = Quaternion.LookRotation (rb.velocity, Vector3.up);
	
		rb.AddForce ((snitch.transform.position - transform.position).normalized*maxAcceleration*Random.value, ForceMode.Acceleration);
		
	}

	void tackled (){
		rb.useGravity = true;
	}

	void OnCollisionEnter(Collision enteredCollider) {
		if (enteredCollider.gameObject.CompareTag ("KillZone") && rb.useGravity)
			Destroy (gameObject);
	}
}

And here is the spawner script:

public class GSpawn : MonoBehaviour {
	
	public int playerCount;
	public GameObject gryfPrefabs;
	GameObject gryClone;
	// Use this for initialization
	void Start () {
		//playerCount = 0;
	}
	

	void FixedUpdate () {
		 
		if(Input.GetKeyDown("d")) { 
			spawnPlayer(); 
		} 

	}

	void spawnPlayer () {
		gryClone = Instantiate(gryfPrefabs,transform.position, Quaternion.identity) as GameObject; 
		gryClone.transform.position = transform.position; 
	} 
}

I have the spawner linked in the inspection window as well. Thank you.

The RigidBody variable rb shouldn’t be marked as static. The Rigidbody will be different for every Gryffindor, when you’re creating a new Gryffindor, the rb variable is assigned the Rigidbody of the new Gryffindor. Therefore the logics in your Update() function will only be executed on the new Gryffindor’s Rigidbody.

You should watch some tutorials on statics, it seems like you’re using them excessively.

So a couple questions to help find the answer.

  1. Can we get a gif or video of the bug?

  2. Can we see the player controller or is there a player control script?

  3. When you spawn another player, use Debug.Log to print out what the current player target is to see if it still has the right reference. Let us know what you get.