I wasnt entirely sure where to put this, as it contains bits of animation, bits of scripting, and bits of whatever else.
So basically, I have a character who is fully animated with idle and walk animations. I want his right hand to constantly follow the mouse, so I use this script
#pragma strict
function Start () {
}
function Update () {
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var pos : Vector3 = ray.GetPoint(5);
transform.position = pos;
}
Pretty basic, but it works. However, it seems on my animated character, the hand wont follow the mouse. Is there anyway to fix this?
I’m not very new to this kind of thing, but the first thing that comes to mind is using OnAnimatorIK.
void OnAnimatorIK (int layerIndex)
{
// Cache the current value of the AimWeight curve.
float aimWeight = anim.GetFloat(hash.aimWeightFloat);
// Set the IK position of the right hand to the player's centre.
anim.SetIKPosition(AvatarIKGoal.RightHand, player.position + Vector3.up);
// Set the weight of the IK compared to animation to that of the curve.
anim.SetIKPositionWeight(AvatarIKGoal.RightHand, aimWeight);
}
This was a script they used for the enemy Ai when they wanted to have his armed positioned wherever the player was at. You could probably do something similiar with this by setting the hand’s IK position and IK weight to the mouse’s position.
Thanks for your help, I wasnt able to ‘get into it’, as I couldnt get it to work. The closest I came was using
And just replacing the OnAnimatorIK, but then it came up with issues with what anim is, I got confused since I dont know what they are either. However, it seems we’re on the right path here