当前位置:网站首页>[Switch]SteamVR 1.x️ 1. Realize hand-object interaction—based on [CameraRig]
[Switch]SteamVR 1.x️ 1. Realize hand-object interaction—based on [CameraRig]
2023-01-19 15:32:41【little girl big】
目录
* 实现目标:
When the handle touches the box,扣动扳机键,拿起盒子(Cube).松开扳机键,放下盒子
a、Get handle reference
b、手柄与Box的碰撞检测
c、获取按钮事件
d、抓取:Boxas a handletransform的子物体,失去rigibody相关属性
e、松开:Box的parent为空,regain itselfrigibody相关属性
* 实现步骤
1、导入SteamVR SDK
2、Delete the originalCamera,拖入[CameraRig]、Create a new box、地面
Adjustable head size:[CameraRig]——SteamVR_PlayArea——Size
3、Get handle reference
The script hangs on the right hand,即Controller (right)

private SteamVR_TrackedObject trackedObject;
private SteamVR_Controller.Device device;
// Use this for initialization
void Start () {
trackedObject = GetComponent<SteamVR_TrackedObject>();
device = SteamVR_Controller.Input((int)trackedObject.index);
}
4、手柄与Box的碰撞检测
给两个Controller添加Sphere Collider,Colliderand scaled down slightly to fit,勾选Is Trigger,给盒子添加Rigidbody

private void OnTriggerEnter(Collider other){ }
private void OnTriggerExit(Collider other){ }
5、获取按钮事件
void Update () {
if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad)){ }
if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)){ }
}
6、手柄震动
device.TriggerHapticPulse(700);7、Implementation of grab and let go events
改变cubeThe parent object of the object,改变cubeWhether to use gravity and dynamicsIs Kinematic
Is Kinematic:是否开启动力学,If enabled, the game is no longer affected by the physics engine,只受transform影响
全代码展示:
using UnityEngine;
public class MyController: MonoBehaviour {
SteamVR_TrackedObject trackedObject;
SteamVR_Controller.Device device;
//Get what you collided withbox
GameObject interactBox;
// Use this for initialization
void Start()
{
trackedObject = GetComponent<SteamVR_TrackedObject>();
device = SteamVR_Controller.Input((int)trackedObject.index);
}
void Update()
{
//按下Trigger键
if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
{
if (interactBox != null)
{
interactBox.transform.parent = transform;
interactBox.GetComponent<Rigidbody>().useGravity = false;
interactBox.GetComponent<Rigidbody>().isKinematic = true;
}
}
//松开Trigger键
if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))
{
if (interactBox != null)
{
interactBox.transform.parent = transform.parent.parent;
interactBox.GetComponent<Rigidbody>().useGravity = true;
interactBox.GetComponent<Rigidbody>().isKinematic = false;
interactBox = null;
}
}
}
void OnTriggerEnter(Collider other)
{
interactBox = other.transform.gameObject;
}
void OnTriggerExit(Collider other)
{
interactBox = null;
}
void OnTriggerStay(Collider other)
{
if (device != null)
{
//触发震动
device.TriggerHapticPulse(700);
}
}
}
大
边栏推荐
猜你喜欢
随机推荐
- 负电压是怎么产生的原理分析
- 迟滞比较器Hysteresiswindow和comparator(窗口比较器)原理
- 残留物与电子PCBA 的可靠性和三防漆涂敷前后可能导致电路板出现故障的变量
- 京东探索研究院 | 2023年十大科技趋势
- A variety of Chinese dialect voice landing applications, Microsoft's intelligent voice unlocks more interactive scenarios
- Is Alipay's annuity insurance worth buying?is it safe?
- Which is the top ten insurance for annuity insurance? Is it safe?
- Use MeterSphere beanshell global assertion reference JSONObject solution
- CNN+LSTM+Attention实现时间序列预测(PyTorch版)
- WebView加载heml代码简单应用
- CTA-Sensitive Behavior-AppOps Solution
- Beyond TensorFlow?Yann LeCun: "Why? PyTorch. That's why."
- 蜻蜓安全工作台程序编排简要说明
- WSL2安装systemd方法
- 安信证券开户安全吗?佣金是万几?
- 大智慧在上面开户安全吗?谁能告诉我一下
- 从合并石子学区间DP
- Golang的基本数据类型-基本使用
- 线扫相机DALSA--卡间同步
- 海康visionmaster-图像Bitmap和CmvdImage互转的方法
- 【threejs】根据点绘制直线
- 【threejs】threesjs 初学场景构建
- 第十三章 UML建模
- 为什么很多年轻人,都被 “伪自律” 给拖垮了?
- 小黑年前实习倒数第二天,又到了开心的疯狂星期四的leetcode之旅:剑指 Offer 27. 二叉树的镜像&&剑指 Offer 28. 对称的二叉树
- Servlet —— Servlet API
- 使用nvm管理node版本(window版)
- typescript学习笔记(三)
- vtkPolyData数据的空间变换
- 深入透析 类的 访问修饰符 public、 protected 、private
- C语言基础 — ( 函数——模块化设计)
- Wider Face+YOLOV8人脸检测
- Wider Face+YOLOV7人脸检测
- 【Android安全】Google Hardware-backed Keystore | SafetyNet | 远程证明Remote Attestation
- [转]SteamVR 1.x️一、实现手与物体交互——基于[CameraRig]
- PHP MySQL Where 子句
- PHP MySQL Order By 关键词
- 我理解的卓越工程
- 各种huggingface分词器对比
- PHP MySQL Order By keywords




