- Home /
How to rotate torso (sub mesh) of a model?
I've been trying to get the upper body / torso of a model (the player one from the AngryBots demo) to rotate to wherever the mouse pointer currently is.
The very simple C# code looks like this:
public Transform UpperBody;
void Start () {
}
void LateUpdate () {
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(ray, out hit, Mathf.Infinity)) {
var hitPoint = hit.point;
var rotation = Quaternion.LookRotation(hitPoint - UpperBody.position);
UpperBody.rotation = rotation;
}
}
The public UpperBody field is set to the root bone (the spine in thise case) of the upper body. And while the model does rotate as I move my mouse, it is not correct as he keeps looking straight up in the air and is rotated away from my mouse:
I've been thinking it probably has something to do with the fact that the origin of the local coordinate system for the spine doesn't have standard up/left/forward angles, like this:
But even if this is the problem, I have no idea of what I need to do make it rotate correctly.
I've also tried doing this UpperBody.LookAt(hit.point, Vector3.left);
to have the UpperBody look at the hit.point and adjusting the world up vector to be Vector3.left which is the up vector for the local coordinate system for the torso
Did you not format your post at all or did UnityAnswers loose the formatting? (it does that sometimes...) anyway, please format. hardly anyone will like to answer to that as is...
what the hell, yeah UnityAnswers ate all the formating apparently. jesus.
Your answer

Follow this Question
Related Questions
Make 2 object not go into each other when modifying one object's position 0 Answers
Unity Rotate Raycast on Quaternion 1 Answer
Automatically rotating objects to fit on to others 0 Answers
Rotate an object from inside (With Flipped Normals) 3 Answers
How can I smooth the rotation using quaternion and raycast? 1 Answer