I'm making a game in a two dimension format and needed help in setting up an aiming system similar to Pocket Tanks: http://www.youtube.com/watch?v=_HiVhsQV0Ow&feature=related
In short you can use the mouse or keyboard to adjust the angle of fire. I can do it in a 3d game using the following code, but it doesn't work in a 2D format. Can someone point me in the right direction?
asked May 02 '11 at 10:08 PM
no problem man!
for mouse aiming, you can use a very similar system to what you're using for 3d, only make a large plane either in the background or foreground that you can use to raycast to using Collider.Raycast to get the mouse pointer position. change the depth axis to the level that your gameplay is on, of course.. so your target position would be made by doing something like: Vector3(hit.point.x, hit.point.y, 0);
then, simply have your character look at that point.
answered May 08 '11 at 12:15 AM
For the keyboard aiming (I haven't done much with mouse aiming..) you can use something like the following:
and then the same, essentially, for your power gauge.
For using the mouse look, the suggestion I have is make an invisible plane along the axis you're using (e.g. if you're locking all the gameObjects to z=0, make the plane along z=0) and then get the intersection from your raycast. From there, you can use some vector algebra to get your aim to follow. Sorry I don't have code ready for this part :(
EDIT: check out some other 2D Mouse Aim questions on here, too; there seem to be quite a few. One that looks promising is here: http://answers.unity3d.com/questions/4464/object-rotates-toward-mouse-2d-top-gameplay/4466#4466