【问题标题】:Unity 2D angular velocity centerunity 2D 角速度中心
【发布时间】:2014-06-24 15:03:29
【问题描述】:

我尝试使用以下命令将角速度添加到我的GameObject

rigidbody2D.angularVelocity = Random.value * tumble;

一切正常,但我希望速度中心在我刚体的中心,但中心在我的GameObject 之外,看起来每次都在不同的地方。如何将旋转中心设置为刚体的中心?

谢谢!

【问题讨论】:

  • 最好在这里问你的问题Unity Answers
  • @TzahMama 这个网站是不是 StackExchange 社区的一部分?因为它非常相似。
  • @DmytroZarezenko 我不这么认为,它只是看起来很像。甚至有些徽章是一样的。

标签: c# unity3d 2d


【解决方案1】:

您可能需要调整您的Rigidbody2D's centerOfMass

我发现最简单的方法是创建一个子游戏对象,将其放置在您想要的重心位置,然后将rigidbody2D.centerOfMass 设置为子对象的transform.localPosition

 rigidbody2D.centerOfMass = someChildObject.transform.position;

【讨论】:

  • 我怎样才能以更好的方式获得该子对象?
  • 我没有看到rigidbody2DcenterOfMass 属性,仅适用于rigidbody :(
  • 我有 Unity 4.3.4 并收到错误:Assets/Scripts/Asteroid.cs(23,21): error CS1061: Type UnityEngine.Rigidbody2D' 不包含 centerOfMass' and no extension method centerOfMass' 类型为 UnityEngine.Rigidbody2D' could be found (are you missing a using directive or an assembly reference?) 的定义
  • 啊,centerOfMass 是在 Unity 4.5 中添加的。
  • 我已经安装了新版本,现在我创建了子对象 centerOfMass 并在代码 rigidbody2D.angularVelocity = Random.value * tumble 之前添加了代码 rigidbody2D.centerOfMass = transform.FindChild("centerOfMass").transform.localPosition 但什么也没有。怎么了?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多