Hi everyone!
Here’s my problem. I suck at rotations, so I don’t really know how I would rotate this.
The thing is, I have three objects. One in the middle, the others on the sides. The ones on the sides move freely, but never rotate. They always look forward. The central object should rotate depending on how the others move. It should rotate so that it always has the other objects at its sides.
“Ok, yes, I also have a point for the head that I could use”
Thanks for reading! I hope you can help me!
Ok I haven’t tried this but I think that it’s right! The position in the centre of the line is calculated by:
var ball1Position = ball1.transform.position;
var ball2Position = ball2.transform.position;
var connectingLine = (ball2Position - ball1Position);
var centrePoint = ball1Position + (connectingLine * 0.5f);
Given that you now need to decide which way to point the centre object- this needs another vector to describe what would be up.
var upVector = Vector3.up; //Or use something else (like the head per @fattie)
Now rotate the line 90 degrees around that axis for the rotation of the object.
yourObject.rotation = Quaternion.LookRotation(Quaternion.AngleAxis(90, upVector) * connectingLine, upVector);
yourObject.position = centrePoint;