- Home /
Question by
DaiMangouDev · Dec 16, 2016 at 12:37 AM ·
c#vector3listeulerangles
How do I add up all the rotations of a Tranform list ?
I have a list of transform and I want to add up these Vector3 eulerAngles/ rotation values at runtime . so I tried the following method and quickly realised that it made no sense and that I don't know at to do here .
public List Targets = new List();
void Updaye()
{
for(int i = 0; i < Targets.Count; i++)
{
transform.eulerAngles += Targets[i].transform.eulerAngles;
}
}
Surprisingly I have not found any sililar questons online . maybe it was too easy to do ? (' ._.)
Comment
Please accept the answer below as the correct answer by pressing the Accept button.
Best Answer
Answer by Fluffy_Kaeloky · Dec 16, 2016 at 12:42 AM
You can multiply Quaternions to combine them :
void Update()
{
Quaternion quat = Quaternion.identity;
for (int i = 0; i < Targets.Count; ++i)
quat *= Targets[i].rotation;
//quat is your combined rotation.
}