- Home /
Moving bones within a playing animation?
I'm struggling to find the fix for my code.
I have a character that is assigned on a 2d plane, think side scroller. When a key is pressed, the animations and movement for the character are stopped. This then triggers the aim script, which is assigned to the characters lower spine bone.
Once the aim script is triggered, all player control scripts are stopped (including animations) The low spine aiming script then tells the character to assume the crouch animation, and hold it until the key has been released.
Heres the problem. Because this crouch animation is playing, the player is unable to use the aim function; which consists of moving the mouse along the y axis to cause the bones to rotate up or down. Every time the mouse is moved, the bones move slightly but are reset to the default animation shape.
Anyway to overide the animations default bone state but keep the character crouched? Thanks, terra.
Here is the aim code:
var rotationSpeed = 300.0; var isEnabled : boolean = false;
var minAngle = -45; var maxAngle = 45;
function LateUpdate () {
if (!Input.GetMouseButton (1)) isEnabled = false;
else if (!Input.GetMouseButtonUp (1)) isEnabled = true;
//localEulerAngles prevent bone snapping, eulerAngles will snap the bones //Following mouse movement, the bones will move when holding right mouse button
if (isEnabled)
{
//stop the dynamic player animations
GameObject.Find("convict").GetComponent("PlatformerPlayerAnimation").enabled = false;
//stop character movement
GameObject.Find("convict").GetComponent("PlatformerController").enabled = false;
//Stop physics collisions
GameObject.Find("convict").GetComponent("PlatformerPushBodies").enabled = false;
//set the character to crouching
GameObject.Find("convict").animation.CrossFade ("Crouch");
GameObject.Find("convict").animation["Walk"].wrapMode = WrapMode.ClampForever;
transform.localEulerAngles.y += Input.GetAxis("Mouse Y") Time.deltaTime rotationSpeed;
// Limit between 90 and 180 degrees
//transform.localEulerAngles.y = Mathf.Clamp(transform.localEulerAngles.y, minAngle, maxAngle);
var angle = transform.localEulerAngles.y;
if (angle > 180) angle -= 360; if (angle <= -180) angle += 360; transform.localEulerAngles.y = Mathf.Clamp(angle, minAngle, maxAngle); }
if (!Input.GetMouseButton (1)){ GameObject.Find("convict").GetComponent("PlatformerPlayerAnimation").enabled = true; GameObject.Find("convict").GetComponent("PlatformerController").enabled = true; GameObject.Find("convict").GetComponent("PlatformerPushBodies").enabled = true; } }
Answer by nantas · Oct 08, 2010 at 04:04 PM
I don't think you can overlap procedural control on the same bone which is playing an animation, but usually it's easy to avoid that, just using properly parenting for different bones and only control the bone with no key frames in game.
In your case, try adding an upper spline bone to control the upper body, and do not put any key frame on this bone during the crouch animation. This way you can control this bone using your mouse even when crouch animation is playing.
Your answer
Follow this Question
Related Questions
Mouse Over Wont Work on Bone Animated Meshes. 1 Answer
Animation with bones, Limb Solver knee is bending in wrong way 1 Answer
Rigging Question: Location of Root bone 0 Answers
Why extra/additional bones don't work with @ animation pipeline? 0 Answers
Swapping Skeleton / Adding bones to a hierarchy and sharing animation 2 Answers