// TODO: Make sure deformation works when the plane isn't at the origin void Deform(float xHit, float zHit) { //int xPos = Mathf.RoundToInt(xHit - transform.position.x); //int zPos = Mathf.RoundToInt(zHit - transform.position.z); xHit -= transform.position.x; zHit -= transform.position.z; xHit /= generator.Scale; zHit /= generator.Scale; int xPos = Mathf.RoundToInt(xHit); int zPos = Mathf.RoundToInt(zHit); float scaledRange = range / generator.Scale; for (int x = (int)(xPos - scaledRange); x < (xPos + scaledRange); x++) { if (x >= generator.resolution) { continue; } else if (x < 0) { continue; } for (int z = (int)(zPos - scaledRange); z < (zPos + scaledRange); z++) { if (z >= generator.resolution) { continue; } if (z < 0 || z >= generator.resolution) { continue; } float xDist = xHit - x; float zDist = zHit - z; float distance = Mathf.Sqrt(xDist * xDist + zDist * zDist); if (distance >= scaledRange) { continue; } float percDistance = distance / scaledRange; float adjustedDistance = deformCurve.Evaluate(percDistance); float deformHeight = heightChange * adjustedDistance * deformDirection; //int scaledX = Mathf.RoundToInt(x / generator.Scale); //int scaledZ = Mathf.RoundToInt(z / generator.Scale); //generator.ChangeVertexHeight(scaledX, scaledZ, deformHeight); generator.ChangeVertexHeight(x, z, deformHeight); } } }