随着父级移动,如何防止子级对象滑离父级?

问题描述 投票:-1回答:1
 public GameObject Miffy;
 void OnTriggerEnter(Collider collider)
 {
     //when space key is pressed and collider is miffy(tagged Player)
     if (Input.GetKey(KeyCode.P) && collider.gameObject.tag == "Player")
     {
         Ball.transform.parent = Miffy.transform;

         Ball.transform.localPosition = new Vector3(0, 0, 0);
     }
 }
 private void Update()
 {
     //when key D is pressed miffy is no longer parent to ball object.
     if (Input.GetKeyDown(KeyCode.D))
     {
         Ball.transform.SetParent(null);
     }
 }

子对象(球)随着父(米菲)对象移动而增加的距离。

c# unity3d 3d parent-child
1个回答
0
投票
您应该

不是嵌套多个Rigidbody或完全移动Rigidbody的父级。

而是使用FixedJoint


Afaik,您可以简单地执行类似操作

FixedJoint

© www.soinside.com 2019 - 2024. All rights reserved.