- Home /
Using Right Analog stick to fire weapon.
I making a top down space shooter similar to Astroids. I want to use my joystick's right analog stick to fire the players weapon similar to any game on PSN or XBLA of the same genre.
How would I acchomplish this in CSharp? Java is also fine if you don't know CSharp.
Answer by spinaljack · Apr 28, 2010 at 12:20 AM
In the input manager you can define extra controls such as the x and y axis of a second joystick (default is accept data from all joysticks so you might want to change that). Assuming the right stick is read as a second joystick, you can use the input from the right stick to aim your weapon similar to walking.
Use the look at function to turn your character to face the direction of the joystick e.g.
transform.LookAt(transform.position + Vector3.( Input.GetAxis ("Horizontal"),0, Input.GetAxis ("Vertical"));
I see, I was wondering about that. Also there is still the need to for some code to make the player rotate depending on the direction the joystick goes. I think I can figure that out, but I would still appreciate any help.
For some reason Unity is not registering my joystick anymore so I will have to put this on hold. Thanks for the answer though it makes sense.
-1 Your assumption that “the right stick is read as a second joystick” is incorrect. Your solution would give you the main (left) stick of a 2nd controller connected to the system— great if you want a strange co-op mode, not so great if you want the game playable by one person. Essentially here, Unity Technologies has mis-labeled “Controller” as “Joystick”.