Hy guys i’m using this script to geneare a collider for each trees.
The x and z pos are correct but i can’t figure out how to make the y works correctly…
this is my code where is the problem??
What’s the error that you’re getting?
Please show it to us. I am not familiar with the terrain api, but I think that I’d be able to help out if I knew what line generates the error.
no the collider is at the center of the gameobject, the problem is that when i instantiate the collider prefab, his x and z position is right but the y isn’t
Documentation says about Terrain.SampleHeight:
Samples the height at the given position defined in world space, relative to the terrain space.
Not sure, but i believe you should add your terrain y pos to this line:
float height = _Terrain.SampleHeight(col.transform.position) + _Terrain.GetPosition().y;
offtop: i had to think for awhile for this one: Vector3.Scale(pTI.position,_Terrain.terrainData.size) …thats clever
Maybe you’re sampling the wrong terrain?
Cause I sampled the height of a terrain that isn’t placed in the scene center, and it worked perfectly fine.
I moved a cube along the x & z axis.
All height were sampled correctly.
And obviously, if you move the terrain upwards, you’ll
have to add the terrain’s y position, just like @TwistOfFat3 & @chelnok said.
What error? ._.
Can you show us multiple screenshot of the scene(from different perspectives)?
I’d like to see how the position isn’t set correctly. is the offset fixed?
Also, make sure that the terrain rotation is set to 0, 0, 0