Sign in to follow this  
ThinkTank

Displaying attack range HUD

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
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this