Arm aiming in 2D. Please Help.

Morning!

I’m creating a game in 3D/2D I mean somthing like Smash Bros, Kirby64 and that kind.

Well, I have a few weeks, so I can not model and animate a character and I’m using the third person prototype from Unity but changing textures and adding armor on him.

My problem is when I try to make his arm follow the mouse because it is preanimated and the interaction cross with the animation, so I want to ask you people if there is some way to take off the arm from the animation or something that let me guide the arm with the mouse.

I’m using this code.

#pragma strict

var mouse_pos : Vector3;
var target : Transform; //Assign to the object you want to rotate
var object_pos : Vector3;
var angle : float;
 
function Update ()
{
    mouse_pos = Input.mousePosition;
    mouse_pos.z = 15; //The distance between the camera and object
    object_pos = Camera.main.WorldToScreenPoint(target.position);
    mouse_pos.x = mouse_pos.x - object_pos.x;
    mouse_pos.y = mouse_pos.y - object_pos.y;
    angle = Mathf.Atan2(mouse_pos.y, mouse_pos.x) * Mathf.Rad2Deg;
    transform.rotation = Quaternion.Euler(Vector3(0, 0, angle));
}

And i know that works cuz all the character rolls in a crazy weird dancing and its cuz the interaction cross with the animation. Well I think thats the reason.

Thnx! I hope you can help me, have a nice day (:

Rotate the arm in LateUpdate instead of Update (animation happens between Update and LateUpdate). You could also just not animate the arm in your animation, though I know for sure that Blender’s default FBX exporter always exports animation for every bone, so unless you can get at its exporter you’ll need to use LateUpdate.

Note that you have to be careful when creating your bones, or your arm’s initial rotation may be such that it’s difficult to rotate without extra work. The bone’s length is one axis; try to get the other axes to point straight up/left for best results.