Sign in to follow this  
RobAU78

Tank Game: Movement Question

Recommended Posts

RobAU78    206
So I've been experimenting with programming a game in pure C/Win32. At first I wasn't sure what kind of game to make, but I've since decided to make a top-down tank game. Right now I'm at the stage where I'm ready to implement a basic sort of tile map, which will require a distinction between world coordinates and screen coordinates. This leads to my question. I'm not sure which way would be better to handle the movement of the player's tank: always keep it centered on the screen (i.e. in the window), or simply keep it viewable on the screen. If I go with the former, I'll scroll the map whenever the player moves; with the latter, I'll only need to scroll it when the player would go "invisible" otherwise. A potential drawback with the latter approach is that the player could get killed at the edge of the map's "viewport" by something he can't see. What do the rest of you think? How do existing tank games handle this?

Share this post


Link to post
Share on other sites
Tiblanc    560
You need to be able to view enough in front of you to cover your firing range and then some.

If your tanks can only fire short distances, then you can put your tank in the center of the screen. If combat is longer range, you can put the camera in front of the turret. Compared to the first method, you will lose a constant point a reference for your position and the player may get dizzy, but that allows you to create longer range battles without making everything tiny.

A fixed screen method would combine disadvantages of both methods. You lose your constant point of reference and you do not allow for longer range battles.

Share this post


Link to post
Share on other sites
Wavinator    2017
What about centering on a point a bit forward of the turret's view so that you see something like 2/3 of the screen real estate ahead and 1/3 behind. I'm not sure if that'd look wonky rotating, but it might give you a feeling of vulnerability to the rear, which would be consistent in terms of right feel.

Alternately if you expect to be attacked from all directions and there's no such thing as hind quarters vulnerability then I think it's best to put the tank in the center. This suggests an action game maybe a bit akin to bullet hell type games. (But of course if you wanted more tactical variety you could not allow shooting while moving, or give shooting a long cool down time, which would be fine even if you're in the center of the screen).

Share this post


Link to post
Share on other sites
apefish    176
I would recommend doing something like Wavinator suggests. I did something like this for a game that I'm working on and it works quite well.

The way I did it, your view direction is controlled by the mouse, so if your mouse is in bottom left corner, you are looking towards bottom left. The trick is that the screen positions itself such that it is halfway between the cursor and the player. This means that the player ends up being opposite the cursor on the screen. I find this nice because you can concentrate on what is close to you, or move the mouse way out to look far (only one screen). I was worried about dizziness or awkwardness when i came up with the idea, but it is actually quite nice and natural.

So the math of it would be get the distance from centre of screen to mouse, add that to player position, and then position the screen centred at that point. screencentreworld = playerworld + (mousescreen - screenmiddle)

I hope this gives you some good ideas, Good luck!

Share this post


Link to post
Share on other sites
RaydenUni    110
For the game I made in grad school we picked a camera that is fixed to the tank, keeping it in the center of the screen. ASWD to move and the mouse to aim.

http://curiositystudios.net/games/tankfrenzy/
http://www.youtube.com/watch?v=hiN-j_ZBFfw

Share this post


Link to post
Share on other sites
RobAU78    206
Thanks guys!

After downloading and trying out WinBolo (it's free), I decided that I'll handle movement basically the same way it does. The screen will follow the player's tank and try to keep it in the center, unless it reaches an edge of the map. Otherwise, the player can scroll the map to look around, but only as far as the tank stays on the screen.

By the way, RaydenUni, that game looks awesome! Great work!

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