I have a really simple script that instantiates objects when the "enemies" object has 0 children, it should spawn in the position of EnemyT, but they fall through the floor and when they spawn properly, their AI doesn't chase the player.

public class spawnmore : MonoBehaviour {

    public Transform EnemiesT;
    public GameObject Enemies;
    public GameObject SpawnedObject;

    void Update () {
        if (Enemies.transform.childCount == 0) 
        {
            SpawnedObject = Instantiate(SpawnedObject, EnemiesT.position, EnemiesT.rotation);
            SpawnedObject.transform.parent = Enemies.transform;
        }
    }
}
  • The code seems correct on the first glance. You are spawning correctly, but it seems like there is a rigidbody on the spawned object which makes it falling through the floor. – M156 Dec 5 at 14:08
  • Deactivate Gravity for the rigidbody or add a collision to your object to have a working collision. – Prometheus Dec 5 at 16:28

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.