2d tank movement control

Hi!
As my first iPhone project I’m making a 2d (of course) tank game. I’ve set up all the iOS-specific stuff and they work fine so that’s why I’m posting here and not specifically in the iOS part of the forum.

I’m having trouble creating a robust steering solution. The user controls the movement with one joystick and the rotation of the turret with the other. I’ve setup so that two dummy objects move away (max a couple of units) from the tanks as the joysticks move away from the center. This was to decouple the movement solution from the joystick input.

What I’d like to do is create some kind of “blackbox” solution where the tank always knows how to move and I just specify where it’s supposed to move. I’d also like the turret to stay rotated in relation to the tank so that if the turret is rotated 25 degrees in relation to the tank and I turn the tank, it should still be rotated 25 degrees in relation to the tank.

Any suggestions?

If you want to be able to click on a position on the screen and have the tank go there then you need some kind of pathfinding system (you might be interested in AngryAnt’s Path system available on the Unity asset store, and there are also loads of other threads about this subject). Keeping the turret’s rotation the same with respect to the tank is straightforward. Just make the turret a separate child object of the main tank and set its rotation using its transform.localRotation property.