So I’m making a tps game and i need the character’s right arm to rotate via script. It needs to aim higher as the camera looks higher (like gta games) when i try to change its transform by script, animator overrides it. I thought of having a blend tree for it, assigning highest and lowest aim animations and make its changing value depended to the camera angle value. but i don’t have those animations and it seemed complex to me. I’m not really good so i’m asking help here. thanks.
Use LateUpdate to apply your modifications after the Animator does its thing and before the frame gets rendered.
yes, or if you want to use the blendtree-approach
you can make the animations in unity, by modifying them (IK or adding rotations)
and recording them
- if you have FinalIK, using a baker feature
- if you have Skele, using its dae exporter, after recording the animation w Scene Motion Capture
void Start()
{
animator = GetComponent<Animator>();
}
void Update()
{
animator.SetBool("pistol_aim", is_aiming);
if(Input.GetMouseButton(1) & !anim.GetBool("sprint"))
{
is_aiming = true;
} else
{
is_aiming = false;
}
}
void LateUpdate()
{
if(Input.GetKey(KeyCode.G))
{
right_arm.Rotate(5 * Time.deltaTime, 0, 0);
}
}
}
So for now i only want my character’s right arm to rotate when i hold g. I tried this but it still doesnt move. Am I missing anything?
The animation will still apply its rotation to the bone every frame, so you are rotating at most 5 * delta time degrees away from where the animation puts it every frame. If you want to rotate that bone entirely on your own you can just store its rotation, apply all your modifications to that stored value, and set its rotation to that value every frame.
Thanks dude, that really worked. I’ve been stuck on this for a month
@dibdab thank you too