Hi,
How can I spawn object on a uneven surface?

I want to spawn the green cubes on this surface and even align the rotation of it, but I can’t seem to figure it out.
Can someone help me with this anoying problem? ![]()
Hi,
How can I spawn object on a uneven surface?

I want to spawn the green cubes on this surface and even align the rotation of it, but I can’t seem to figure it out.
Can someone help me with this anoying problem? ![]()
Couple questions.
Are you using Unity Terrain as your play surface or are you using an object / mesh etc?
What is the problem with the objects now, and what script are you using for spawning, duplication or instantiation?
Need more details before anyone will be able to help.
I agree with grayfenix, however if your going to try and work it out yourself, a hint would be ray casting. You can get the position where it his, and an angle that you can convert to a rotation. You can also use the normal of the face you hit.
I am doing something similar, using terrain (and not a mesh). I have been kind of avoiding the problem for the moment, but if the solution is more simple than I figured I’d love to hear it!
It’s very easy on Terrains:
Right but as rickgude said, what about the rotation of the object? I am wanting to make them instantiate flush with the ground, at the same angle/incline as the terrain.
Read up RaycastHit in the documentation. You can find the point where you hit as RaycastHit.point and the normal as ReycastHit.normal - then you instantiate at the point position and use the normal to find your desired rotation.
You can also get the terrain normal via terrain.terrainData.GetInterpolatedNormal, though you have to convert from world to terrain space. Raycast is probably easier.
Is there a function how to do this or do I have to calculate it manually?
What could the code for this look like?
how can i do this with a mash
Please don’t hijack 10-year-old threads for new questions. Start your own post… it’s free!
Generally you can either sample terrain height as listed above, or else use collision and raycast to sample heights if it is a mesh.