OnTriggerEnter and position problem
Hey everybody,
I'm pretty new to Unity and c#, so I might struggle with something easy :P
Current situation: I'm programming a little game, where a ball needs to hit a trigger and then the trigger instantiate two new objects. The new objects should be placed in a special place which I provide in the script.
Let's say that the trigger is on "0,10,3" and should be placed on "0,20,3". In my case, the new object will be instantiate on "0,19.51,3". I think, it's because 19.51 is the very edge of the collider.
Script:
public class CreateObject1 : MonoBehaviour
{
public GameObject cylinder;
public GameObject triggerBox;
private Vector3 spawnPosition;
private void OnTriggerEnter(Collider other)
{
Debug.Log("Trigger: New enemy");
spawnPosition = other.attachedRigidbody.position;
Instantiate(cylinder, spawnPosition + new Vector3(0, 7, -3), Quaternion.Euler(0, 0, 0));
Instantiate(triggerBox, spawnPosition + new Vector3(0, 10, 0), Quaternion.Euler(0, 0, 0));
}
}
Do you guys have an idea, how to get the center position? I mean if this is really my problem :P Sure, I could just make the collider really small, but since it should create the objects (one is a new collider) dozens of times, the problem would still occur in a matter of time.
Thank you! :)