Mouse click handling: Large ground plane vs ground plane that move with camera

Hi,

For a RTS style overview camera, I am wondering which approach is better to handle mouse click in the game scene.

  • have a very large static quad at xz plane, with a collider.
  • have a large enough quad at xz plane, with a collider, that move with the camera.

All I want is to handle mouse click in the scene (xz plane). My camera is perspective and with a small FOV, I currently use ScreenPointToRay and the 2nd option to get the world point.

But with camera zoom I now have to manage the scale of the quad, which need to cover the camera view cone’s intersection with xz plane, it’s hard to calculate that without using extra rays (there is ViewportToWorldPoint but we don’t know the z “depth” beforehand).

I am wondering if I am over-engineering this? The first approach seems like a bad idea?

Thx in advance.

(PS: a side question, can someone explain to me when does a post belongs to “Editor & General Support” and when does it belongs to “General Discussion”?)

Not sure about the question, but the way I always achieve this is a navigation mesh and navmesh agent, and use the screen to world point, I believe.

There’s a good tutorial on Unity learn for this, I will dig it up later today.

I think you are making too much of this. Both approaches will work, and are straight forward to implement. Just pick one and run with it.

Neither; use the Plane class. No need to create any GameObjects for it.

3 Likes

Yep, ray-plane intersection has to be lighter weight than maintaining some geometry and checking against that, and is surely more elegant than adding geometry to the scene.

That is, of course, assuming that you’re only ever interacting with a plane.

Good suggestion, Plane.Raycast is exactly what I need :slight_smile: