I’m trying to instantiate an object on top of another one. To do this I decided to draw raycast from above the first object and instantiate next object on hit.point. however. for some reason it always instantiates the object on y 0.05. this means the raycast goes through collider and reaches this very specific point.
here’s some other helpful info
the object we cast a ray on is a child of an empty game object. this object has a cube collider, not set to trigger, no rigidbody. there is no other object located before or after the object raycast needs to hit. There’s nothing on 0.05y.
here’s the relevant bit of code
if (Physics.Raycast(RayPos, transform.TransformDirection(Vector3.down), out hit,
Mathf.Infinity))
{
int ChosenFlora = Random.Range(0, biome.Flora.Length);
print(hit.point);
Instantiate(biome.Flora[ChosenFlora], hit.point, Quaternion.identity);
Debug.DrawRay(RayPos, transform.TransformDirection(Vector3.down) * 1000, Color.cyan);
Debug.LogError("stop");
}
This piece of code is a part of a procedural world generation project. and it’s task is to spawn trees, bushes, and other plants on top of existing tiles. this code is executed for each tile after everything else has been generated