Background Context
I'm currently developing a strategy game that combines elements from both Europa Universalis 4 and Age of Empires 3. The game is being created using JavaScript and the Three.js (r109) library. At this stage, I have successfully implemented randomly generated low-poly terrain with trees and realistic water reflections. In the initial stages of the game, I aim to spawn a Navy unit in the form of a galleon (as shown in the screenshot below). My goal is to ensure that when this unit spawns, it does so at a random location within the boundaries of the water. The water surface is depicted by a semi-transparent plane covering the entire map area, supported by a THREE.Reflector
object below it. While the terrain also consists of a plane, its appearance has been altered using a SimplexNoise heightmap.
https://i.sstatic.net/lhzJO.png
The Query
How can I effectively identify whether an x,z position intersects with the water mesh rather than the terrain mesh? While I believe THREE.Raycaster
could be beneficial for this task, I am curious if there might be a more optimized solution available. If utilizing THREE.Raycaster
is indeed the ideal approach, how should I proceed with implementing it specifically for this scenario? Is it necessary to create separate instances of THREE.Raycaster
for each object involved? Note that my objective is not to place this object using mouse input; instead, I intend to determine its placement through a method that assesses the position mentioned earlier.