【发布时间】:2020-02-06 19:01:23
【问题描述】:
大家好,我正在尝试相对于另一个子游戏对象旋转一个子游戏对象。例如,如下面的层次结构所示,我正在尝试分别相对于它们的直接父级 PA_DroneWingLeft(和 PA_DroneWingRight)旋转 PA_DroneBladeLeft(和 PA_DroneBladeRight)。我希望这些刀片旋转到位。相反,我让它们在 y 方向上相对于主要父级(Air Drone)全局旋转。我认为我注释掉的 Update 方法中的那行应该有效,它确实有效,但它仍然相对于 Air Drone 旋转而不是到位。第二行,RotateAround 方法 我尝试创建一个名为 Left Pivot 的空游戏对象,并将其放置在左翼中心附近,并让左刀片围绕该中心旋转,但没有用。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LeftBladeRotation : MonoBehaviour
{
GameObject leftBlade;
private float speed;
private float angle;
GameObject leftPivot;
// Start is called before the first frame update
void Start()
{
speed = 10f;
leftBlade = transform.Find("PA_DroneBladeLeft").gameObject;
angle = 0f;
leftPivot = GameObject.FindGameObjectWithTag("Air Drone").transform.Find("PA_Drone").transform.Find("PA_DroneWingLeft").transform.Find("Left Pivot").gameObject;
}
// Update is called once per frame
void Update()
{
angle += speed * Time.deltaTime;
Quaternion rotation = Quaternion.Euler(new Vector3(0f, angle, 0f));
//leftBlade.transform.localRotation = rotation;
leftBlade.transform.RotateAround(leftPivot.transform.localPosition, Vector3.up, angle);
}
}
【问题讨论】:
标签: unity3d rotation transform local quaternions