我有一个游戏对象,它沿着它的一个轴来回摆动,这个对象附着在围绕场景移动的父GameObject上。但是,当父对象旋转时,子对象不会随之旋转。使旋转对象与父对象一起旋转
我希望这个事情做与当地VS全球空间。但是林茫然......
这是管理的扫码。
// Increment a timer
timer += Time.deltaTime;
// Swing the object back and forth based on the rotationLimit and the rotationSpeed
currentRotation = Mathf.PingPong (timer * rotationSpeed, rotationLimit * 2f) - rotationLimit;
// Create a temporary variable to store the new rotation
Quaternion rotation = Quaternion.Euler (transform.rotation.x, transform.rotation.y + currentRotation, transform.rotation.z);
// Set the rotation to the temp var
transform.rotation = rotation;
我考虑抓住父母的旋转和使用,而不是transform.rotation。然而,理想情况下,同一个脚本需要处理各种对象,其中一些对象没有父母。任何人都可以告诉我哪里出错了。