So I want to be able to instantiate a gameobject into the scene by the click of the mouse. I have it all figured out except one part, how would I make the instantiate ‘origin point’ to be the bottom of the gameobject, not the middle. Because when I spawn in objects, it looks like it’s instantiating them from the middle, making the object intersect and look weird. I just want to be able to place objects on top of other colliders, no intersecting involved.
Here’s my C# code:
void Update () {
if (Input.GetMouseButtonDown(0)) {
//Creates the raycast hit variable
RaycastHit hit;
//Creates the ray variable, set to origin at the center of the camera that the script is attached too
Ray ray = camera.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0));
//Starts the logic: if the raycast hits a collider, it will spawn (Instantiate) the prefab
//obj is the prefab
//hit.point is the location in which the ray collided
if (Physics.Raycast(ray, out hit)) {
if (hit.collider != null) {
Instantiate(obj, hit.point, Quaternion.identity);
}
}
}
}