- Home /
how can I transform a capsule by its two center
I have a capsule (and I don't care about the collider ) but I wont to place it by it's two center like if the q0(0 , 0 , 0 ) and the q1( 1, 1,1) how can I compute the angle that should I rotate to fit the requirement
Answer by destructivArts · Dec 22, 2016 at 08:30 PM
Just to summarize what you want: 1. Specify two points 2. Rotate and scale the capsule so that the centers of each cap sit a those two points.
Supposing the two points are A and B and the centers of each cap are q0 and q1, and the default distance between q0 and q1 is capsuleLength which equals 1, I'd do the following.
Make sure that your capsule's long axis is along the x axis when its rotation transform is zero. (ie. when the capsules
rotation = Quaternion.identity, q1 = q0 + Vector3.right * capsuleLength
).Rotate the capsule by
Quaternion.FromToRotation(Vector3.right, (A - B).normalize)
Set the position to be
(A + B) / 2
Set the scale of the capsule to
(A - B).magnitude
Your answer
Follow this Question
Related Questions
Unity Character Controller messing up. 0 Answers
Weird compilation error regarding Instantiate 0 Answers
Getting screenshots within a loop? 2 Answers
Assigning unchanged position to transform 0 Answers
Constraint on localScale - how to? 1 Answer