Hi Everyone, I am developing my first game. I have a character i have made with Mecanim to control its movements, (using the 45min mecanim video given by Unity) Currently my character can stay idle, walk forward with left and right motion and run forward with left and right motion as well as go backwards. However i also want to allow my character to simple pivot in the idle position around the game world (without moving forward or backwards) so when i press the left key it simple rotates the player left around the gameworld (along with the camera) and if the user presses the right key then the character pivots right (along with the camera). Im not sure if this animation or a scripting problem I hope someone can help!! Thank you I have also included the control script if that is needed Code (csharp): using UnityEngine; using System.Collections; // Require these components when using this script [RequireComponent(typeof (Animator))] [RequireComponent(typeof (CapsuleCollider))] [RequireComponent(typeof (Rigidbody))] public class GirlControlScript : MonoBehaviour { [System.NonSerialized] public float lookWeight; // the amount to transition when using head look [System.NonSerialized] public Transform enemy; // a transform to Lerp the camera to during head look public float animSpeed = 1.5f; // a public setting for overall animator animation speed public float lookSmoother = 3f; // a smoothing setting for camera motion public bool useCurves; // a setting for teaching purposes to show use of curves private Animator anim; // a reference to the animator on the character private AnimatorStateInfo currentBaseState; // a reference to the current state of the animator, used for base layer private AnimatorStateInfo layer2CurrentState; // a reference to the current state of the animator, used for layer 2 private CapsuleCollider col; // a reference to the capsule collider of the character static int idleState = Animator.StringToHash("Base Layer.Idle"); // these integers are references to our animator's states static int locoState = Animator.StringToHash("Base Layer.Locomotion"); // and are used to check state for various actions to occur public bool IsAlive = true; void Start () { // initialising reference variables anim = GetComponent<Animator>(); col = GetComponent<CapsuleCollider>(); if(anim.layerCount ==2) anim.SetLayerWeight(1, 1); } void FixedUpdate () { if(IsAlive) { //Debug.Log("hi"); float h = Input.GetAxis("Horizontal"); // setup h variable as our horizontal input axis float v = Input.GetAxis("Vertical"); // setup v variables as our vertical input axis anim.SetFloat("Speed", v); // set our animator's float parameter 'Speed' equal to the vertical input axis anim.SetFloat("Direction", h); // set our animator's float parameter 'Direction' equal to the horizontal input axis anim.speed = animSpeed; // set the speed of our animator to the public variable 'animSpeed' anim.SetLookAtWeight(lookWeight); // set the Look At Weight - amount to use look at IK vs using the head's animation currentBaseState = anim.GetCurrentAnimatorStateInfo(0); // set our currentState variable to the current state of the Base Layer (0) of animation RaycastHit hit; if (Physics.Raycast(transform.position, Vector3.forward, out hit)) { v = 0; } //Debug.DrawRay(transform.position, fwd); if(anim.layerCount ==2) layer2CurrentState = anim.GetCurrentAnimatorStateInfo(1); // set our layer2CurrentState variable to the current state of the second Layer (1) of animation } else { } } }
Hi, did you solve the problem ? I'd follow the same tutorial as you, and have the same issue that you had. I want to pivot my character, even when he is in his idle animation. I've made a nice blend tree, following this video : So i've made the blend trees, it works fine in the previews, but then, the scripts that the guy give in his video to tell to your character to pivot dosent work, and i dont know what can i add in my script ( bot control script ) that i already have, witch was in the tutorial you saw too, to make my character play the pivot blend trees that i've made. Best
Do you find the solution yet? i use unity 5 and all that guy script have was messed up in unity 5, it say all compiler error and have to be fixed.
You asked for simple so here it is. You can simply rotate the character when idle based on mouse rotation (or keys if you wish) transform in this case is the player GameObject (and the character model) This is called in FixedUpdate for me. I hope this is what you meant; Code (CSharp): float rotY = Input.GetAxis("Mouse X"); // Get the Yaw Input if (currentBaseState.fullPathHash == idleState){ transform.Rotate(0, rotY, 0);} // Apply Mouse rotation to model if idle (can look around)