Unity3D: Rotate Object Around Y-Axis Using Mouse Drag
Vector3 cross = Vector3.Cross(new Vector3(eventData.delta.x, eventData.delta.y), Vector3.forward).normalized;
// Set the Y component of the cross vector to 0 to only rotate around the Y-axis
cross.y = 0f;
cross.Normalize();
// Use the modified cross vector to rotate around the Y-axis
if (_Model != null)
{
_Model.transform.Rotate(cross, eventData.delta.magnitude * 0.3f, Space.World);
}
This modified code sets the Y component of the 'cross' vector to 0 before normalizing it. This ensures that the rotation only occurs around the Y-axis.
原文地址: https://www.cveoy.top/t/topic/qx5V 著作权归作者所有。请勿转载和采集!