【发布时间】:2020-07-22 16:47:12
【问题描述】:
我试图通过触摸移动我的播放器并使其发生碰撞,所以我编写了这个脚本,但问题是我的播放器没有与其他对象发生碰撞,那么如何让它发生碰撞,那么如何解决这个问题?
[SerializeField] private Rigidbody rb; private Vector3 targetPosition; private void Start() { targetPosition = transform.position; if (!rb)rb = GetComponent<Rigidbody>(); // since this rigibody is going to be moved via code not Physics it should be kinemtic rb.isKinematic = true; // in order to smooth the movement rb.interpolation = RigidbodyInterpolation.Interpolate; } void Update() { if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Moved) { targetPosition += Vector3.right * touch.deltaPosition.x * speedmodifier; targetPosition += Vector3.forward * touch.deltaPosition.y * speedmodifier; } } } private void FixedUpdate() { rb.MovePosition(targetPosition); }
【问题讨论】:
-
确保您的对撞机不会太薄,然后重试。
-
@MathewHD 对撞机就像我的播放器
标签: c# unity3d 3d rigid-bodies