[英]Unity Spawning GameObjects with Hinge Joints
I'm working on a level generator in Unity for an endless runner and I want to spawn some prefabs with hinge joints. 我正在Unity中为一个无尽的奔跑者制作一个关卡生成器,我想生成一些带有铰链接头的预制件。
The trouble is that when I spawn an object with a hinge joint, it retains the anchor and connected anchor from when the prefab was saved, not relative to its spawned position. 麻烦的是,当我使用铰链关节生成对象时,它保留了保存预制件时的锚和连接的锚,而不是相对于其生成位置。
Any idea how I can fix this? 知道我该如何解决吗?
Instead of having the joint in the prefab. 而不是在预制件中使用接头。 Why don't you use the
AddComponent<HingeJoint>
method in runtime when you generate the level to do the connections. 生成级别进行连接时,为什么不在运行时中使用
AddComponent<HingeJoint>
方法。
I solved this problem with adding an Rigid Body(IsKinematic=true) as parent and set the Connected Rigidy Body
property to this. 我通过添加一个刚体(IsKinematic = true)作为父级来解决此问题,并将“
Connected Rigidy Body
属性设置为此。 Spawning the parent keeps the Connected Anchor
in place. 生成父对象可使
Connected Anchor
保持在原位。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.