Hello.
I’m trying to set rig.weight = 1f where my character starts aiming inside of Update, but it never changes the value. The value change works if I place it somewhere outside of aiming.
I can manually set the rig’s weight before hitting Play, so I can see the end result of what I want with the ARigging working, but I also cannot change the rig’s weight on the fly.
Any ideas what’s preventing me from changing the value here?
private void Update() {
Vector3 mouseWorldPosition = Vector3.zero;
Vector2 screenCenterPoint = new Vector2(Screen.width/2f, Screen.height /2f);
Ray ray = Camera.main.ScreenPointToRay(screenCenterPoint);
if(Physics.Raycast(ray, out RaycastHit raycastHit, 999f, aimColliderLayerMask)) {
debugTransform.position = raycastHit.point;
mouseWorldPosition = raycastHit.point;
}
if (starterAssetsInputs.aim)
{
crossHair.gameObject.SetActive(true);
aimVirtualCamera.gameObject.SetActive(true);
thirdPersonController.SetSensitivity(aimSensitivity);
thirdPersonController.SetRotateOnMove(false);
animator.SetLayerWeight(1, Mathf.Lerp(animator.GetLayerWeight(1), 1f, Time.deltaTime * 10f));
Vector3 worldAimTarget = mouseWorldPosition;
worldAimTarget.y = transform.position.y;
Vector3 aimDirection = (worldAimTarget - transform.position).normalized;
transform.forward = Vector3.Lerp(transform.forward, aimDirection, Time.deltaTime * 20f);
rig.weight = 1f;
Debug.Log("Aiming");
if(starterAssetsInputs.shoot)
{
//shooting stuff
}
return;
}
else
{
crossHair.gameObject.SetActive(false);
aimVirtualCamera.gameObject.SetActive(false);
thirdPersonController.SetSensitivity(normalSensitivity);
thirdPersonController.SetRotateOnMove(true);
animator.SetLayerWeight(1, Mathf.Lerp(animator.GetLayerWeight(1), 0f, Time.deltaTime * 10f));
rig.weight = 0f;
Debug.Log("Not Aiming");
}
}
It looks like there’s conflict with when changing the animation layer through the script at the same time, but I’m able to have the second layer working along with manually setting the rig’s weight to 1, so I don’t understand why this isn’t working.
Proof of manually setting the weight to 1 with the second animation layer active:
The spine bone is affected by ARigging to get the vertical body rotation and the arms are animated by the idle anim in the Aiming layer.
What could be causing me to be unable to change the rig weight through script?