Hi,
This is my first post in unityAnwsers. I am not sure if I framed my question right but what I want is to position an object on a certain point on a rotating object. I do not want the rotating object to have any children and want to make this code based (just for the fun of it… and learning).
Here is a picture explaining what I want :
[33791-rotationposition.png!|33791]
Here is my attempt at it so far. It is not working as intended :
This is just a guess as I can’t test it right now but I’ll post it anyways.
If I’m not misunderstanding anything then you just need the position of the cube, the offset of the corner position and the rotation. You should have all of that. Let’s assume your corner is at (1,0,1) from the center of the cube.
What I’m doing is take the offset rotate it by the rotation of the cube and add the rotated offset to the position of the cube. Should be as simple as that at least in my head :D.
I guess all your answers are correct, but I found the fault in my code. Actually transform.rotation returns a quaternion angle not vector angle, so instead of using ‘transform.rotation.z’ I used ‘transform.rotation.eulerAngles.z’ which gave the rotation in degrees and then converting that to radians gave the correct answer.
Just in case if anybody has the same problem, here is the code :
var zRotation = transform.rotation.eulerAngles.z
//Pythagoras Theorem
var radius = Mathf.Sqrt(Mathf.Pow(transform.localScale.x/2, 2) + Mathf.Pow(transform.localScale.y/2, 2));
//Subtract 45 degrees to get the corners of the object
tempObject.transform.position = this.transform.position + new Vector3(Mathf.Cos(zRotation - 45) * radius, Mathf.Sin(zRotation - 45) * radius, 0f);