How to use Virtual reality controllers to create an Amazing bow and arrow Experience in STYLY

Hello Everyone! Today we are going to learn how to use Virtual reality controllers to create an amazing bow and arrow experience. Please make sure you are following the tutorial in a series so you are clear on how to access controllers. Also make sure you have read the STYLY X Playmaker tutorial series here. The basic reason for this tutorial is to guide users on how to infuse kinetics and elasticity into objects. The gist of the tutorial is to multiply a constant with the distance between the 2 hand held controllers for virtual reality. You can checkout a simple Archery scene I created using UNITY X PLAYMAKER X STYLY here.

 

To start off, download free bow and arrow models from 3dwarehouse.sketchup.com. Make sure to turn the models into prefabs and making them a child of an empty object. We will do this as sometimes; models can be tricky to deal with so it is better to envelope them in a game object. 

Now that we have the prefabs ready, setup the uploadable prefab for STYLY. Follow the setup state in this tutorial. Once one of the controller is ready, simply copy that object, duplicate it, change its name to whatever seems appropriate. You will need to change a few other things such as the name of the object you are trying to find from “Controller (right)” to “controller (left)”. Similarly, change event names from “Global_TriggerDown_R” and “Global_TriggerUp_R” to “Global_TriggerDown_L” “Global_TriggerDown_L”. If you feel you have no idea about what I am talking about, please read this tutorial.

7.JPG
8.JPG

Once both the controllers are setup, play around with the new models placement until you feel the placement of the objects is realistic in Virtual Reality. Once done, move on towards setting up the right controller which is what I will be using as an arrow.

State 1 is empty. State 2 is where we create the object. Notice how the transitions in the state machine help release only 1 arrow at a time.

3.JPG

Now the fun part starts. We want the arrow to go the furthest when our arms are stretched and we are in an archery position. We do not want the arrow to go too far if the arrow has not been pulled back enough. The key here is distance. The distance between the 2 controllers. We can simply get the distance in 3 easy actions in the arrow. We will use the following actions:

 

  • Find Game object (find: “Controller (left)”, store in: Controller_L )
  • Find Game object (find: “Controller (right)”, store in: Controller_LR)
  • Get distance (Game Object: controller_L, target: controller_R, store in: forceMultiplyer)

 

9.JPG

Now that we have the distance, we need to multiply it with a constant so we can get the resulting force we want to apply to the arrow. For that we will use Float multiply action to get a force. I multiplied the forceMultiplyer with 5000. Now add the resultant into the z axis of the arrow and keep the world set to self. Finally, reset the forceMultiplyer variable to zero by using action Set Float Value. We now have simple bow and arrow dynamics. This version is still faulty and works even if the arrow is not pointing to the bow. We can fix this issue by continuously pointing the arrow towards the bow by using the action Look at.

 

Congratulations! You can now enjoy practicing your archery skills. 

10.JPG

For URDU or HINDI version of this tutorial, please click here.

 

 

 

Created by: Abdullah Sajjad