Hello fellow Unity devs,
I humbly come before you again with another problem that’s got me stumped. Here’s the issue:
I have a continuously scrolling background in a 2.5d game which creates new ‘world chunks’ whenever an ontriggerenter2d event is called. The new world chunk is instantiated using the position and rotation of an empty game object called SpawnPoint. Here’s what that code looks like:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Instantiate_Trigger_Script : MonoBehaviour {
Vector3 refPoint = new Vector3(0, 0, 1);
public GameObject spawnPoint;
public GameObject WorldChunk;
// Use this for initialization
void Start () {
transform.position = Camera.main.ViewportToWorldPoint(refPoint);
spawnPoint = GameObject.Find("SpawnPoint");
}
void OnTriggerEnter2D(Collider2D collision)
{
Instantiate(WorldChunk, spawnPoint.transform.position, spawnPoint.transform.rotation);
}
The problem I’m facing is that all my new world chunks are being instantiated slightly off target and are not flush with their neighbor as a result. I’ve attached an example of what I’m seeing to the thread.
Any suggestions on how to fix this would be greatly appreciated. Thank you all for your help.



Thats weird it shouldn’t be doing that. Is the position of the chunk in the inspector the same as the position of the spawn point after instantiation? If it is then maybe the chunks geometry is offset a bit in the chunk prefab??
Hi Adam,
Thanks for responding. I have confirmed that the location of the parent object and the spawn point are indeed the same after instantiation. It’s worth mentioning that the parent object’s location is not the location of the sprites. Each sprite is a child of the world chunk container object. I’ve already done the math on how far apart these things are, so it should be on target when it works right.
Hello world,
After a month of distractions and struggle I come back to you all with the knowledge of why this was happening.
I used a circle collider in combination with an edge collider to trigger the instantiation of each new world chunk. While the circle collider is small–it has a radius of 0.2 units–the instantiation of each new world chunk occurs when the EDGE of the circle collider touches the edge collider. Since the edge of the circle collider is 0.2 units away from the point I need it to trigger at it was throwing off the precision I needed for this.
This doesn’t fully solve my problem–I’m still working with different collider types to get the triggering to happen when I want–but we all know what went wrong now.
I know this is kind of a “Duh!” solution, and it probably shouldn’t have taken me this long to figure it out, but I wanted to leave record of what went wrong so that those who follow in our footsteps don’t repeat my mistake.