简体   繁体   中英

(Unity)How to rotate child object regardless of orientation?

So I have 4 objects, which all have childs underneath. I want to rotate these childs slowly when a button is pressed.

Example: Spacebar is pressed, and for all 4 parent objects I want to rotate the child down slowly. Problem is, they need to use the same script, but all of their orientations are different.

So if I do the following: 在此处输入图像描述

Childs of parent 1 move down perfectly, but childs of parent 2 move to the left and right, because they have a different orientation. When I rotate them by hand in Unity, for parent 1's childs I need to move the Y axis to get them to rotate down, but for parent 2's childs it's the Z axis.

How can i always move it down regardless of any orientation?

Rotate

has an optional parameter relativeTo . By default it is set to Space.Self what you want is Space.World so do

pBone.transform.Rotate(Vector3.right * _boneMoveSpeed * Time.deltaTime, Space.World);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM