Jump to content

  • Log In with Google      Sign In   
  • Create Account

Selecting Units


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Qaia   Members   -  Reputation: 104

Like
0Likes
Like

Posted 05 September 2012 - 10:11 AM

What's the preferred method to select units with the mouse, i.e., you have a unit on screen that you want to either control or see its stats and you hover your mouse over the unit and click to select it?

I was thinking of reading the (x,y) screen coordinates (not the world coordinates) of the unit and comparing that with the (x,y) mouse coordinates. But I'm not sure if this approach is commonly used or efficient. I was also thinking if it would be possible to associate a hitbox with the mouse and project that into the world.

Are there other approaches commonly used?

Sponsor:

#2 kidman171   Members   -  Reputation: 419

Like
0Likes
Like

Posted 05 September 2012 - 10:23 AM

The technique you are looking for is called ray casting. In most cases you need to take the screen coordinates, normalize them, and cast a ray from that origin. Next you check for collisions with that ray. If you are using a graphics or game engine, its likely they have a built-in ray casting feature.

#3 CC Ricers   Members   -  Reputation: 623

Like
0Likes
Like

Posted 05 September 2012 - 10:48 AM

The technique you are looking for is called ray casting. In most cases you need to take the screen coordinates, normalize them, and cast a ray from that origin. Next you check for collisions with that ray. If you are using a graphics or game engine, its likely they have a built-in ray casting feature.


Also, as a point becomes a ray when projected in 3D, a rectangle would become a frustum. So if you plan in the future on also doing rectangle selection to select several units at once, you would create a smaller sub-frustum inside your viewing frustum and use that to check what units are intersecting it. But for clicking on one unit, a ray is all you need.
My development blog: Electronic Meteor




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS