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;
}
}