How Pico SDK controls movement in Unity

How to carry out actual development after Unity imports Pico SDK? Everyone must be very curious. From last year's provincial competition to this year's national competition, I have been studying Pico for almost a year. When I first started learning, I read a lot of blogger articles, but I couldn't find the knowledge I wanted. Since then, I have been After making up my mind, I will write about the use of virtual devices after the national competition, so I will explain the correct use of Pico SDK from my perspective.

The main content today is the movement method of Pico SDK in the first-person perspective in Unity

The picture below shows that the Pico SDK has been imported into Unity3D

1. Delete the Camera camera that comes with Unity, find the Pvr_UnitySDK subfolder Prefabs, and drag the Pvr_UnitySDK prefab under the Prefabs folder into the scene, then the camera is ready.

2. Find the ControllerManager prefab under the Pvr_Controller folder and put it into the scene, which becomes a child object of Pvr_UnitySDK, which is at the same level as the Head in Pvr_UnitySDK. Pvr_UnitySDK refers to the headset, Head refers to the player's head, ControllerMannager refers to the handle controller, PvrController0 is the left controller, and PvrController1 is the right controller.

3. Find the Scenes folder under the Pvr_Controller folder, open the Pvr_Controller_Demo scene in the Scenes folder, find the sub-object HeadControl of Pvr_UnitySDK, put it in the Assets directory, and then return to the previous scene, the steps are shown in the figure below

4. Put the HeadControl under the Assets directory into Pvr_UnitySDK, which is at the same level as Head and ControllerManager. The rendering is as follows

5. Add the script Pvr_Input Module (Script) to the Event component. This script comes with PicoSDK. You can add it directly. There is a Confirm Btn option in the Pvr_Input_Module script. Here you can choose the event button for the player to interact with the UI. The default is to select TouchPad, the black rounded button of the handle;

6. Add the script Pvr_Controller Demo (Script) to the ControllerManager component. The Pvr_Controller Demo (Script) script comes with the PicoSDK folder, just add it directly;

7. Open the script of Pvr_Controller Demo (Script) in the ControllerManager component, add the ray click movement method on the script, and the added code is shown in the figure

 

 As shown in the figure, the added ray detection movement code is complete, the code is as follows:

   //Add
    public Transform person;//Moving character
    public string moveLayer;//Moveable layer
    public LineRenderer rayLine_zengjia;//ray_LengthAdaptive under the handle;

//New addition

 if (1 << hit.transform.gameObject.layer == LayerMask.GetMask(moveLayer))
 {             rayLine_zengjia.material.color = Color.green;//When the ray becomes movable                       if ( Controller.UPvr_GetKeyDown(0 , Pvr_KeyCode.TRIGGER) || Controller.UPvr_GetKeyDown(1, Pvr_KeyCode.TRIGGER) || Input.GetMouseButtonDown(0) )                         {                             person.position = new Vector3(hit.point.x, person.position.y, hit.point. z);                         }  }                     else                     {








                        rayLine_zengjia.material.color = Color.red;//The ray turns red when it is immovable
                       
                    }

8. Perform the following operations on the ControllerManager component, the steps and effect diagrams are as follows

9. Create the ground. Here I created a 3D object Cube, set the Layer property of the Cube object, and set the Layer property to moveLayer, indicating that this is a movable layer. The steps are as follows

 10. At this point, PicoSDK has completed the first-person roaming in Unity3D. When the handle trigger is pulled, the point where the handle ray points is the target point for the first-person player to move.

11. Alt + left mouse button is the trigger button of Pico,

        In the future, I will also tell you about another way of moving Pico.

        If you are interested in Pico, you can read my other articles

If you have any questions, you can add me to chat with WeChat at yf1553653788

Guess you like

Origin blog.csdn.net/Ai1114/article/details/125209941