- Home /
Instantiate in the right position
Hi! I just made a random enemy random spawner thingie, basically it chooses one of the different enemies and instantiates it at a random spawnpoint, the problem is hat they spawn where they shouldn't I mean, some go trought the ground some don't even touch it, anyway I can fix this? btw my instantiate line:
GameObject enemyInstance = (GameObject) Instantiate (enemies[pickEnemy], spawns[pickSpawn].transform.position, spawns[pickSpawn].transform.rotation);
Obviously your spawns collection contains object that are in the wrong position according to you.
yeah, but different enemies have different size... and if I set it good for one enemy, the others will be wrong
Then you can just use the height of the "enemy" to deter$$anonymous$$e an offset. It's just some simple math and vector algebra.
Answer by fransh · Jul 22, 2013 at 11:19 PM
Either the pivot of your spawners, or the pivot of your enemies, or the combination of both is causing this problem i think.
Make sure that if you place a object in the scene, and you put the position to 0,0,0 it actually is on the right position, just as you wanted it to be if you would imagine a floor there on 0,0,0 as well for example.
If it is not, and the distance you must move the object to look correctly placed, equals the distance you see between your spawns and their spawn locations right now, than you found your problem.
Your answer
Follow this Question
Related Questions
How to implement a system for "Road-Construction"? 1 Answer
Wrong particle and prefab spawn position 1 Answer
blocks being placed in an odd way 0 Answers
Not instantiating prefab in the right place after 2017 update 2 Answers
Keep instantiated GameObject's position while parenting it to another GameObject 3 Answers