I am trying to get my character to be able to crossfade into his attack while running. The character runs with “d”, and attacks with “mouse 0”. I need the character to be able to use “mouse 0” while “d” is pressed and without it. Currently it works if the character isn’t running/moving, but will not crossfade/play if the character is moving. The
| | statement on line 58 is what I have tried and is not working. Thanks.
** The game is a 2.5D sidescroller, with basic WASD movement, and attacks with mouse 0 1 **
CURRENT CODE
// Player Script : Movement
// Inspector Variables
var playerSpeed : float = 5.0; // Players Speed
private var moveDirection : int = 0; // Decides which way character is facing
private var isIdle : boolean = true;
var rightShoulder : Transform;
function Update () {
// Clamp Rotation to 90
// Character Movement
// RIGHT
if (Input.GetButton ("Move Right"))
{
moveDirection = 0;
transform.Translate (0, 0, playerSpeed * Time.deltaTime);
}
// LEFT
if (Input.GetButton ("Move Left"))
{
moveDirection = 1;
transform.Translate (0, 0, playerSpeed * Time.deltaTime);
}
// JUMP
if (Input.GetButtonDown ("Jump2"))
{
rigidbody.velocity = Vector3 (0, 12, 0); // Jumps in air
rigidbody.velocity.y -= 4;
}
// Animations Attacks
if (rigidbody.velocity.z > 0) // Run Right
{
animation.CrossFade("CRun");
}
else if (rigidbody.velocity.z < 0) //Run Left
{
animation.CrossFade("CRun");
}
else if (Input.GetButtonDown ("Swing One")) //Swing1 Attack
{
Swing1();
}
if (rigidbody.velocity.z == 0 isIdle == true) // Idle
{
animation.CrossFade("CIdle");
}
// Animation MIXING
var runIsPlaying : boolean;
if (animation.IsPlaying ("CRun"))
{
runIsPlaying = true;
}
if (Input.GetButtonDown ("Swing One") runIsPlaying == true) // Swing while running
{
animation["CSwing1"].AddMixingTransform(rightShoulder);
}
// Variable setup for eulerAngle assignment used on LEFT and RIGHT movement
if (moveDirection == 1) // Left
{
transform.eulerAngles = Vector3(0, -90, 0);
}
if (moveDirection == 0) // Right
{
transform.eulerAngles = Vector3(0, 90, 0);
}
}
// Adjust character sliding problem
if (transform.position.z > -1)
{
transform.position.z = -1;
}
if (transform.position.z < -1)
{
transform.position.z = -1;
}
// Function that sets up Swing1 Delay
function Swing1 ()
{
isIdle = false;
animation.CrossFade("CSwing1");
yield WaitForSeconds (animation["CSwing1"].length);
isIdle = true;
}