- Home /
Accouting for random rotations in Rotate Around
I have a randomly generating tube moving towards and around the camera along the z axis. The tube is maid up of strait pieces and curved pieces. The curve will approach the camera, with the rest of the tube extending outwards, in what ever direction the curve is bending towards(imagine a bendy straw). When the curve gets the camera it must rotate so that the following pieces will move strait towards the camera. Innitially I had it set up that each curve had a set pivot point, the whole tube would rotate around it so that everything was in a strait line again. But then I started having the tube rotate around the z axis randomly so that the tube with bend off in different directions. My problem is I can't figure out a consistent way to rotate the entire tube so that it will be strait after a curve. Can anyone think of a good way that can consistently turn it? I have a feeling that it could be solved by chaining the axis for rotate around, but I'm not sure the best way to manipulate it. This is the current code for it:
`transform.RotateAround (child.FindChild("Turn").FindChild("TurnChild").position, Vector3.right, -41.4276);`
I've added some pictures of what it looks like, 1. before the rotation, when not randomly rotated, 2. after rotation, when not randomly rotated
Answer by aldonaletto · Aug 19, 2012 at 02:29 AM
I'm not sure about exactly what you're trying to do, but suppose that you want the parts to behave like a single piece, rotating around some fixed pivot - am I right? If so, create an empty object at the pivot position and child all segments to it. Move or rotate the empty object, and all children will keep their relative position/rotation, behaving like a single object.
The good news is, your theory is right, the bad news is thats the part that I have working so far. the issue is the pivot point I have will be at a random xy coordinate when I need it, so once I found it I have to figure out axis to rotate it around. when the pivot point is directly up or down its Vector3.right, when directly left or right its Vector3.up. So I am looking for something that can take the pivot point's XY coordinate and give me a proper Vector3 axis to rotate around. Sorry my original question wasn't too clear.