イミディエイトジオメトリ（ImmediateGeometry）ノードとGodotの他のメッシュとのZファイトを防ぐには、イミディエイトジオメトリ（ImmediateGeometry）ノードの頂点をカメラに近づけることができます。これは、スクリプトでImmediateGeometryの頂点配列を操作することで可能です。

頂点をカメラに近づけるには、各頂点のZ座標を変更すればよい。カメラと他のメッシュの距離から新しいZ座標を計算し、そこから小さな値を引くことで、ImmediateGeometryをカメラに少し近づけることができます。

以下にコード例を示します：

```
var immediate_geometry = $ImmediateGeometryNode
var camera_position = get_viewport().get_camera().get_global_transform().origin
var distance_to_camera = camera_position.distance_to(other_mesh_position)
var vertices = immediate_geometry.get_mesh().surface_get_arrays(0)[0]

for i in range(vertices.size()):
    var vertex = vertices[i]
    vertex.z = -distance_to_camera + 0.01  # 0.01 is a small value to ensure distance from camera
    vertices[i] = vertex

immediate_geometry.get_mesh().surface_set_arrays(0, [vertices])
```

このコードでは、immediate_geometryは移動させたいImmediateGeometryノード、camera_positionはカメラの位置、other_mesh_positionはZファイトを引き起こしている他のメッシュの位置、verticesはImmediateGeometryのメッシュの頂点配列です。

forループは配列の各頂点を通過し、カメラまでの距離から新しいZ座標を計算し、頂点のZ座標を新しい値に設定します。最後に、変更した頂点配列をイミディエイトジオメトリのメッシュに戻します。

Godotでのイミディエイトジオメトリノードとその頂点配列の操作については、Godotドキュメント[4]と関連するGodot Q&Aスレッドを参照してください。

この解決策が最も効率的で最適とは限りません。また、特定の状況においてZ-fightingを防ぐ他の方法があるかもしれません。さらに、望みの効果を得るために、カメラまでの距離に加える値を実験する必要があるかもしれません。
To prevent Z-fighting between your ImmediateGeometry node and another mesh in Godot, you can move the vertices of the ImmediateGeometry node closer to the camera. You can do this by manipulating the ImmediateGeometry's vertex array in your script.

To move the vertices closer to the camera, you can simply modify the Z-coordinate of each vertex. You can calculate the new Z-coordinate based on the distance between the camera and the other mesh, and then subtract a small value from it to ensure that the ImmediateGeometry is slightly closer to the camera.

Here is some example code to get you started:



var immediate_geometry = $ImmediateGeometryNode
var camera_position = get_viewport().get_camera().get_global_transform().origin
var distance_to_camera = camera_position.distance_to(other_mesh_position)
var vertices = immediate_geometry.get_mesh().surface_get_arrays(0)[0]

for i in range(vertices.size()):
    var vertex = vertices[i]
    vertex.z = -distance_to_camera + 0.01  # 0.01 is a small value to ensure distance from camera
    vertices[i] = vertex

immediate_geometry.get_mesh().surface_set_arrays(0, [vertices])

In this code, immediate_geometry is the ImmediateGeometry node you want to move, camera_position is the position of the camera, other_mesh_position is the position of the other mesh that is causing Z-fighting, and vertices is the vertex array of the ImmediateGeometry's mesh.

The for loop goes through each vertex in the array, calculates the new Z-coordinate based on the distance to the camera, and then sets the vertex's Z-coordinate to the new value. Finally, the modified vertex array is set back onto the ImmediateGeometry's mesh.

For more information on ImmediateGeometry nodes and manipulating their vertex arrays in Godot, you can refer to the Godot documentation [4] and a related Godot Q&A thread.

Note that this solution may not be the most efficient or optimal, and there may be other ways to prevent Z-fighting in your specific situation. Additionally, you may need to experiment with the value added to the distance to camera to achieve the desired effect.