0

Create virtual right joystck for aiming and shooting

spoo.sangal 2 years ago updated by CSmith 2 years ago 1

I am making a fixed camera 2d shooting game, i want my character to be able able to shoot in any direction and i want to set the direction using right joystick and as soon as i let it go it fires the projectile in that direction 

Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):

I’m sure there are assets on the asset store for pre-made virtual joysticks. But from scratch, obviously have your graphics for your outside circle and where the “point in the circle" is (Or however you want it to look). But to make the joystick have use, you need to detect touches in that area, when the touch is 'down' The joystick in one state where it is under control of the position of your touch but within a distance from the center of the joystick as a constraint. When you release the touch, it goes into a “Shoot and rebound” transition where it sends out it’s direction and velocity relative to the center of the joystick then you can use a tween to pop it back to the center.

In bolt I would definitely use my fave part of bolt : the state machine. Set up these 2 states (and I usually have an init state to initialize it before it goes into the default - untouched state). Then when it’s touched, this transitions into the pointing state where you follow your finger with constraints.  Then when untouched from this state, have a transition back to the idle state that fires off the direction and velocity for your character to shoot and triggers the tween animation back to center.