- Home /
Question by
yahyouch36 · Oct 08, 2020 at 12:34 PM ·
rotationmesh
Control Avatar Mask Through Code
is there anyway I can change the avatar mask with code ? for example : in a Third Person Shooter if player presses MouseButton(1), I want my character to look at the mouse input ( the legs of the character should play the idle animation and the spine should rotate) , else I want it to play the idle animation normally with both spine and legs. I tried the idea of getting the spine of it's original parent so I can rotate it, and then put it back to resume the animation of the spine with this code:
public Transform spineToRotate;
public Transform spineParent; // I want to set it back to the parent so the animation plays normally
void FixedUpdate(){
if (Input.GetMouseButton(1) ){
// getting the spine out of parent so it wouldn't be effected by animation so I can rotate it , otherwise I can't
spintToRotate.SetParent(transform);
RotateSpine();
}else{
spineToRotate.SetParent(spineParent);
}
}
void RotateParent(){
angle -= Input.GetAxis("Mouse Y")*spineRotationSpeed*Time.deltaTime;
angle = Mathf.Clamp(angle,minimumAngle,maximumAngle);
SpineToRotate.localRotation = Quaternion.AngleAxis(angle,Vector3.right);
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613013349im_/https://answers.unity.com/themes/thub/images/avi.jpg)