- Home /
Rotation Complications + rotation with parents and children?
Hi there, I have been trying to make objects rotate in a variety of ways. I am working on a scene in which the user can construct something out of a variety of prefab game objects. This involves being able to move, scale and rotate the objects, much like you do in unity itself. I have stumbled across two problems doing this (one of which I have got stuck on in another scene).
Problem 1: I think this is a standard problem, but when using eulerAngles, the rotations glitch out like crazy. It is impossible to rotate past 90 degrees in certain rotations, and rotating in certain axis buggers up other axis. I understand there is a problem wwith eulerAngles due to the translation between the quaternions and the eulers. I have also experimented with the quaternianEuler, but I can't see how that is any different to using eulerAngles. Is there any way to stop the eulerAngles glitching out or do I need to start learning how quaternions work?
Problem 2: I want to be able to point mmy object in any direction, and then be able to rotate it on an axis based on the direction in which it is facing, just like if I was making a space sim and wanted to roll the ship (which I am, and I also can't get that to work properly, haha!). I have read a million unity answers pages and looked through countless tutorials, but I can't seem to find anything that works properly.
My current solution to this is to have a parent layer which points the object in the correct direction, then a child layer which holds everything in the object, and use the child layer for local rotation, ie rotating the object around axis based on the direction it is facing. This feels to me like unnecasary clutter though, and I'm sure there must be a better way. I am also wondering if having the extra child with it's own transform merely for extra rotation will add any extra cpu strain, bearing in mind I intend for the user to be able to add as many of these building blocks as the computer can handle.
Sorry about the essay, any thoughts on this would be much appreciated. Cheers in advance,
Pete
Answer by iron_attorney · Jun 12, 2015 at 03:54 PM
Ok sorry, I've totally sussed this out, using:
transform.rotation = Quaternion.AngleAxis(1, transform.forward) * transform.rotation;
it was a piece of cake once I found the correct quaternion function. I've already managed to implement this on my space sim aswell, got roll pitch and yaw all working. Awesome!
Pete
Your answer
Follow this Question
Related Questions
Trouble Spawning Bullets with proper rotation 0 Answers
How do I make transform.Lookat use Vector3.down instead of Vector3.forward? 1 Answer
Gyro Sensor based on Euler angles? 0 Answers
Rotating child object around X and Z from different angles causing issues 2 Answers
Object deforms with rotation 1 Answer