• Advertisement
Sign in to follow this  

Displaying attack range HUD

This topic is 2923 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

Hello, I am creating a tower defense game and I want to display the graphical attack range of a tower to the player when they are trying to place a tower on the grid. The attack range is circular, with it's center point being the tower itself. It should be about 50% transparent in order to see the terrain below it that it encompasses. The attack range varies depending upon which tower type you are trying to place on the grid. A good example of this is in League of Legends when you select an ability from your champion. Is this done via decals using the depth/stencil buffer, or is there some other method? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
What graphics API are you using? Also, from what point of view is the game viewed? (That is, is it 2-d, 3-d, top-down, isometric, etc.)

Share this post


Link to post
Share on other sites
Sorry, I should have mentioned that earlier.

I am using the Unity engine. My game is in 3d with a traditional RTS style camera (like warcraft 3).

Share this post


Link to post
Share on other sites
Height-map?

If so, the simplest would be decals: you copy the polygons of the terrain, that the circle lies on, you calculate texture coordinates (that's the tricky part: paper an pen), then you draw it with blending.

I hope that helps, I can give more details if you like.

Share this post


Link to post
Share on other sites
Can you go a little bit further into detail? I'm still a bit unclear of the process. Do I need a flat circular model that I apply a texture to in order to display this effect?

Share this post


Link to post
Share on other sites
No, you have to copy the polygons of the terrain mesh, that enclose the circle.
(Note, this is only good, when you have only one circle, because it will be overdrawn on the scene with blending. So too much of them will reduce the performance, but one is just fine). I'm pretty sure that Warcraft III does it like this (as decal).

See image (top view of terrain):
image

You have to determine the enclosing polygons first: determine the indexes inside the green square. (you can do this if you know the center and the radius of the circle). I suggest you to make this work at first: draw these polygons with a constant color, so you can see if it works good.

The red square is the full the circle texture (reds are the edges of it) it would be after texturing (it's so hard to describe, i think you get it).
You can see, that the texture coordinates need offsetting (du,dv texture units), we can do that:

dx,dy are the distances between the center of the circle and the center of the green square. (world units)
du = -dx/x_size_of_green_square_world_units;
dv = -dy/y_size_of_green_square_world_units;

You need to translate texture coordinates with these.
initial texture coordinates: dark blue numbers in image: if the green square is 4x4 terrain grids.

You can see that the green square is bigger than needed, this makes calculations easier. When it comes to drawing, draw only the light blue squares.

I hope that's clear and helps you.

BTW is there a better-than-paint (and free) tool to make drawings like this?

Share this post


Link to post
Share on other sites
Thank you very much for the detailed explanation and picture. I'm assuming most of this work has to be done on the gpu?

Share this post


Link to post
Share on other sites
No, it's pure CPU.
Warcraft III don't use shaders, so it can't do it on GPU.
But if you can, you can make this effect with a shader, but the method is totally different.

This is the thing

But if you want to do it on the CPU, I can give you even more details...

Share this post


Link to post
Share on other sites
A cheaper method but less fidelity: Make a ring model with an alpha'd texture, put the pivot at the center, child this ring to the base of your tower model and then scale accordingly

Share this post


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

  • Advertisement