Hi Unity fans,
This is a project that is a “2.5D shooter game” where I want to make the Player to face that direction where the “green arrow” is pointing, while the “red arrow” is showing where the Player is walking backwards.
But my problem is that it keeps playing the average walking animation where its walking forward when I want to play the “WalkBack” animation. I need help to make the Player face a certain direction then plays the “WalkBack” animation. I tried different methods but just don’t know how.
Please help
#pragma strict
var anim : Animator; //Hold a Animator
var body : Transform; //Tranform the armature of the player model
var mousexThreshold = 0.2; //Number of units for the mouse to move on x-axis
//Settings for the Upper Body rotation
var sensitivityY = 15F;
var minimumY = -60F;
var maximumY = 60F;
var rotationY = 0F;
function Update () {
if(Input.GetButton("a")){
anim.SetBool("Walk",true); //Edit true and false
}
if(Input.GetButton("d")){
anim.SetBool("Walk",true); //Edit true and false }
}
if(Input.GetButtonUp("a")){
anim.SetBool("Walk",false); //Edit true and false
}
if(Input.GetButtonUp("d")){
anim.SetBool("Walk",false); //Edit true and false }
}
if(Input.GetButton("Fire1")){
anim.SetBool("Shoot",true);
}
// Tranform the rotation of the player when mouse moves on the x-axis
var mousex : float = Input.GetAxis ("Mouse X");
if (mousex > mousexThreshold)
{
transform.forward = new Vector3(1f, 0f, 0f);
}
else if (mousex < -mousexThreshold)
{
transform.forward = new Vector3(-1f, 0f, 0f);
}
}
function LateUpdate(){
// will make the upper body of the model to be rotatable
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
body.transform.localEulerAngles = new Vector3(0, rotationY, 0);
}
This is the code I made so far.