如何用C#中的浮子计算
我想以Unity进行编程地形生成器,并为Perlin Noise Terrain Generator提供了一些工作代码。我目前正在使用Unity(使用C#),我无法弄清楚如何将地形深度(Z)的产生分开(我想使用SQRT功能来计算的山脉/山谷的高度),这取决于X和地形深度取决于y。我的问题是,当我尝试将浮子转换为ints时,我将不得不将它们围起来,否则它们无法正常工作,但是我想平稳地计算地形,我可以将这2个高度组合成1个高度而不粗糙而结合起来地形?
float CalculateHeights(int x, int y)
{
float xCoord = x;
private int xz = float xCoord;
float yCoord = (float)y / height;
private int yz =float yCoord;
int z = (xz + yz) / 2;
return Mathf.Sqrt(z);
}
I want to programm a terrain generator in Unity and already have some working code for a Perlin Noise Terrain Generator. Im currently using Unity (using c#) and i cant figure out how to seperate the generation of the terrain depth(z)(the height of the mountains/depth of the valleys which i want to calculate using a Sqrt function) depending on x and the terrain depth depending on y. My problem is, when i try to convert the floats into ints, i would have to round them up or else they wont work, but i want to calculate the Terraindepth smoothly, is there a way i can combine those 2 heights into 1 without roughening the terrain?
float CalculateHeights(int x, int y)
{
float xCoord = x;
private int xz = float xCoord;
float yCoord = (float)y / height;
private int yz =float yCoord;
int z = (xz + yz) / 2;
return Mathf.Sqrt(z);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您试图在Unity中使用Perlin噪声,则可以随时使用内置的发电机。
例如:
警告:如果您不使用此功能使用X和Y的浮点值,那么您将始终获得相同的值。
希望这会有所帮助。
docs- https://docs.unity3d.com/scriptreference/scriptreference/mmathf.perlinnoise.htmll < /a>
If you're trying to use Perlin Noise in Unity, you can always use the inbuilt generator.
Ex:
Warning though: If you don't use floating point values for X and Y with this function, you'll have issues with always getting the same value.
Hope this helps.
Docs - https://docs.unity3d.com/ScriptReference/Mathf.PerlinNoise.html