Jump to content
  • Advertisement
Sign in to follow this  
mrnoob

RTS - box in units

This topic is 3773 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, ive been trying to figure out how to do this but i cant think of anything. i need to be able to draw a box with a health bar around selected units, like in most RTS games, but im not sure how to. im guessing something to do with selection mode, but i cant be sure. Whats the usual way to approach this? thanks

Share this post


Link to post
Share on other sites
Advertisement
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, windowwidth, 0.0, windowheight, -1000.0, 1000.0);

With this kind of projection, it becomes easy to position 2D things on screen.

Quote:
im guessing something to do with selection mode

Selection mode doesn't draw anything on screen.

Share this post


Link to post
Share on other sites
ok, i guess i didnt really explain what the problem i was having was.

drawing in ortho mode isnt the issue, its working out where in 2d coordinates a unit is, finding its boundaries in 2d terms, and drawing a box around it.

Share this post


Link to post
Share on other sites
Ok follow along on this as I haven't done this, but this is how I would do it.

You can use glUnProject or do the math yourself with rays to get the units that you clicked on. Now that unit should have its own position x,y,z coordinates stored somewhere. You now build a box around it with the box bottom is where the units bottom is at and the size of the box you can decide to make a set size which may cause issues with larger units or you determine the largest size each individual unit is and make the box taylored to each unit that way. You can make your own function e.g. DrawBox(float x, float y, float z, float size) and call this to make the box around the units....

HTH and you are following what I am suggesting.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!