ViveInputUtility-handle to pick up 3D objects (7)

This chapter mainly introduces how to use VIU to pick up 3D objects and trigger picking events.

1. Pre-preparation
Create a new scene 06-3DGrab, delete the default camera, create an empty node Player at the origin, and drag the required modules into the Player node. This chapter will continue to use the teleportation scene in Chapter 2 as the basis for explanation, using stairs and walls To test the pickup function of the handle.
insert image description here
2. The handle picks up 3D objects. It
is very simple to make 3D objects have the function of being picked up. You only need to mount the Basic Grabbable component on the 3D object with a collider.

3. Detailed Explanation of Basic Grabbale Components
insert image description here
(1) Ovveride Max Angular Velociry: Overrides the maximum angular velocity
(2) Unblockable Grab: Unblocked pickup
(3) Primay Teleport Button: The first pickup button, here you can set the first pickup button , will be detected first, and generally no setting is required.
(4) Secondary Teleport Button: The second-order pick-up button has a lower priority than the first-order detection. Here, the trigger button is used by default, and it is generally set to the trigger button/hold button.
(5) Allow Multiple Grabbers: Turn on the two-handed picking interaction, which can realize common functions: pick up objects with both hands to zoom in and
out .
(7) Min Stretch Scale: Scale minimum value, take effect when two handles are picked at the same time
(8) Max Stretch Scale: Scale maximum value, take effect when two handles are picked at the same time

4. Pickup event trigger
In the above component diagram, you can see that the component comes with AfterGrabbed, BeforeRelease, and OnDrop events, which represent the three states of after picking up, before releasing, and released. Write the
Demo6_VRGrab script and mount it on the ladder and wall at the same time. On, trigger prerequisite: Collider has been mounted on the object

using HTC.UnityPlugin.Vive;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Demo6_VRGrab : MonoBehaviour
{
    
    
    private BasicGrabbable basicGrabbable;

    private void Awake()
    {
    
    
        basicGrabbable = GetComponent<BasicGrabbable>();
    }

    private void Start()
    {
    
    
        basicGrabbable.afterGrabberGrabbed += BasicGrabbable_afterGrabberGrabbed;
        basicGrabbable.beforeGrabberReleased += BasicGrabbable_beforeGrabberReleased;
        basicGrabbable.onGrabberDrop += BasicGrabbable_onGrabberDrop;
    }

    private void BasicGrabbable_afterGrabberGrabbed()
    {
    
    
        Debug.Log($"{
      
      transform.name} 拾取后");
    }

    private void BasicGrabbable_beforeGrabberReleased()
    {
    
    
        Debug.Log($"{
      
      transform.name} 松开前");
    }

    private void BasicGrabbable_onGrabberDrop()
    {
    
    
        Debug.Log($"{
      
      transform.name} 已松开");
    }
}

In the development process of VR projects, picking is also one of the longest-used functions, such as: picking up parts and installing them in a fixed position. After learning this chapter, it is not difficult to get along
. Prompt
(2) Perform collision detection before the part is released, judge the installed position, and perform correct/error prompt logic processing
(3) The part has been released, and the installation position stops highlighting
insert image description here

Guess you like

Origin blog.csdn.net/weixin_38484443/article/details/127320658