Could someone please tell me if Unity allows for scripting manual bone control (in-game).
It does. I tested some IK code I was playing with a while back.
You will see your bones in the hierarchy, those are the objects you script the rotation for.
-Jeremy
In unity, bones are treated like normal transform hierarchies and therefore can be manipulated in any way. Its quite nice. Technically, the trick is to lerp in between the current position and a new position in LateUpdate(). That has the effect of blending in between whatever procedural thing you do and the original animation.
So are you saying that I could control the exact movement (rotation) of a characters arm by say, mouse movement? If so this engine sounds like it would suite my needs perfectly. Thanks for all the replies.
Yes you could, but to do it properly you would need to write some IK control code yourself. I ported some CCD IK (cyclic coordinate descent) to use with Unity, and it works quite nice.
If however, you just want to rotate one bone, depending on mouse movement, that is easy. I am assuming you want the whole arm to follow the mouse, which would require IK.
HTH,
-Jeremy
Hell yes. The code looks like this:
// the scary broken arm movements, probably:
var shoulder : Transform;
var shoulderControl = 0.9;
var elbow : Transform;
var elbowControl = 0.4;
var hand : Transform;
var handControl = 0.1;
private var currentDirection : Vector3 = Vector3.forward;
// animation is applied every frame in between Update() and LateUpdate().
// doing this in LateUpdate has the effect of blending between
// our procedural rotation for the arm bones and the pre existing one.
function LateUpdate ()
{
currentDirection.x = Mathf.Clamp(currentDirection.x + Input.GetAxis("Mouse X"), -1, 1);
currentDirection.y = Mathf.Clamp(currentDirection.y + Input.GetAxis("Mouse Y"), -1, 1);
var rotation : Quaternion = Quaternion.LookRotation(currentDirection);
shoulder.localRotation = Quaternion.Slerp(shoulder.localRotation, rotation, shoulderControl);
elbow.localRotation = Quaternion.Slerp(elbow.localRotation, rotation, elbowControl);
hand.localRotation = Quaternion.Slerp(hand.localRotation, rotation, handControl);
}
// but you can make it as complex as you like, as procedural animation often needs to be complicated
Wow, thanks heaps for the help and so quickly. ![]()