How can I make my character turn back and continue running?
How can i make my character turn back instead of doing Running in forward(animation)and moving backwards).I want to rotate him by 180 degrees. Also what is the best way I could make him Jump as well as Sync his Mixamo animation so that it appears as if he's Jumping .
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityStandardAssets.CrossPlatformInput; public class Controls : MonoBehaviour { static Animator anim;
public float speed = 10.0f;
public float rotationSpeed = 100.0f;
//Jump Mech Tools............
public Vector3 jump;
public float jumpForce = 2.0f;
public bool isGrounded;
Rigidbody rb;
//Jump ...............
// Use this for initialization
void Start()
{
anim = GetComponent<Animator>();
rb = GetComponent <Rigidbody >();
jump = new Vector3(0.0f, 2.0f, 0.0f);
}
void OnCollisionStay()
{
isGrounded = true;
}
// Update is called once per frame
void Update()
{
float translation = CrossPlatformInputManager.GetAxis("Vertical") * speed;
float rotation = CrossPlatformInputManager.GetAxis("Horizontal") * rotationSpeed;
translation *= Time.deltaTime;
rotation *= Time.deltaTime;
transform.Translate(0, 0, translation);
transform.Rotate(0, rotation, 0);
Debug.Log("Translation = "+translation+ "\n"+"Rotation ="+rotation );
if(CrossPlatformInputManager.GetButtonDown("Jump") && isGrounded){//ad
anim.SetTrigger("isJumping");//added
anim.SetBool("isRunning", false);
anim.SetBool("isIdle", false);
rb.AddForce(jump * jumpForce, ForceMode.Impulse);//ad
isGrounded = false;//ad
}
// if (CrossPlatformInputManager.GetButtonDown("Jump"))
// { anim.SetTrigger("isJumping");}
if (translation != 0)
{
anim.SetBool("isRunning", true);
anim.SetBool("isIdle", false);
}
else
{
anim.SetBool("isRunning", false);
anim.SetBool("isIdle", true);
}
}
}
Comment