Version: 2021.3

Gyroscope.userAcceleration

切换到手册
public Vector3 userAcceleration ;

描述

返回用户给予设备的加速度。

该值的重要性在于系统已消除重力(也由加速度计检测) 的影响,只留下用户移动的加速度。

using UnityEngine;

public class Example : MonoBehaviour { Vector3 forceVec; Rigidbody rb;

void Start() { rb = GetComponent<Rigidbody>(); }

void FixedUpdate() { // Apply forces to an object to match the side-to-side acceleration // the user is giving to the device. rb.AddForce(Input.gyro.userAcceleration.x * forceVec); } }