MENU
Learn Technologies

Unity RPG Zombies Killer Part 2

In this video you will learn how to make RPG game:
– Right joystick (Turn player and Fire)
– Capsule

TurnPlayer method:

In this part of tutorial, we add the Right Joystick, it’s responsible for making player turn and fire. So, it has priority over the Left Joystick to manage player rotation.

1
2
3
4
5
6
7
8
9
10
11
private void TurnPlayer()
   {
       if(RightJoystick.IsPressed)
       {
           var turn = new Vector3(RightJoystick.Direction.x, 0f, RightJoystick.Direction.y);
           Quaternion quaternion = Quaternion.LookRotation(turn);
           rigidbody.MoveRotation(quaternion);
           transform.rotation = quaternion;
           Fire();
       }
   }

Player Shooting:

Let’s add “Fire” method. When player presses the right joystick, we launch capsule in the player direction with the defined fire rate:

1
2
3
4
5
6
7
8
9
private void Fire()
   {
       if(fireCountDown <=0)
       {
           GameObject capsule = Instantiate(CapsulePrefab, FirePoint.transform.position, FirePoint.transform.rotation);
           fireCountDown = 1f / fireRate;
       }
       fireCountDown -= Time.deltaTime;
   }

Follow Me For Updates

Subscribe to my YouTube channel or follow me on Twitter or GitHub to be notified when I post new content.

0 0 votes
Article Rating
Subscribe
Notify of
guest


0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x