- Home /
Aim at target with animated character.
Hi.
I have a 3rd Person camera behind my player and it's looking at one target (aimTarget), I want the player points its arm at that aimTarget by rotating bones. Player has a mecanim controller. Technically I want to make a shoot animation by code. Using Unity Free so I can't use IK (I think). I've tried this already:
function LateUpdate(){
var aimDir = aimTarget.position - shoulder.transform.position;
shoulder.transform.localRotation = Quaternion.Lerp(shoulder.transform.rotation, Quaternion.LookRotation(aimDir), Time.deltaTime * 20.0);
}
Used LookAt an localEulerAngles but just get crazy arm movements. Thanks.
Answer by ZenithCode · Sep 07, 2013 at 07:07 AM
Don't rotate bones. You just need to play an aiming animation.
To get the rotation you can use a layer of the head, or simply rotate the whole character from its origin. (This will not look as good as a top body look at animation though)
It's hard to make an animation since I have run, walk, strafe, walkback etc animations in mecanim, I'd have to make lot of animations
Not really, use the same locomotion animations and use layers to mask the animations for the right and left hands only.
Thanks, I'll try that, but I also want an ai$$anonymous$$g pose in all axis while running, walking,etc.
That's more reason why you should use blending. This will make your life easier by creating less animations.
Create a new layer
Create a new mask
Choose the arm bones only
Watch this! It should help: http://www.youtube.com/watch?v=Xx21y9eJq1U&feature=youtu.be&t=43m40s