- Home /
How to Fire a projectile using the right Thumbstick?
Hey all, I was playing around dual thumbsticks for Android games like Gun Bro's, Guerrilla Bob and others. Does anyone know how they make the right stick instantiate a projectile in the players facing direction based on the right Thumbsticks location? Any help or insight on this would be appreciated!
Can you offer more details? Are you talking about physical sticks of some sort or virtual? Have you looked through any of the documentation for unity yet? Have you given this a shot? Have you searched this site for similar questions?
Answer by Dan · Jul 07, 2011 at 11:13 PM
So you need to:
1) Detect when the joystick is being used.
2) Detect which direction the joystick is pointed.
3) Instantiate a projectile at predetermined intervals when the joystick is being used.
4) Make the projectile move in the direction the joystick is pointed upon instantiation.
You can use the Dual Joystick prefab in Standard Assets (Mobile). I think it outputs a Vector2 to show direction and magnitude of the joystick input, which solves issues 1 and 2. If either the x or y is > 0, you can instantiate a projectile prefab. You can create a timer that counts down, fires, and resets to create an "automatic weapon" effect. That solves issues 3. To make the projectile move, you can make it a Rigidbody and add set the force of it right after it instantiates. If you set the X and Y values of the force you add to the X and Y values of the joystick's Vector2, they should move in the direction you had the joystick pointed.
design3 has some more tutorials on creating weapon firing in Unity, including how to implement that auto-fire timer.
Your answer
Follow this Question
Related Questions
GUI Joystick 1 Answer
help, 3d android game joystick 1 Answer
Andriod Multitouch with joystick 1 Answer
Camera Facing Forward on Android 0 Answers
How to avoid sticky corners when moving around using joystick? 1 Answer