- Home /
 
               Question by 
               jamiewhitephd · Sep 28, 2014 at 10:51 PM · 
                animationrotationtransformcontrollermecanim  
              
 
              Top-down character running animation based on facing direction
Hi there,
I have a character containing animations for running - forwards, backwards, strafe left and strafe right. I have all of the controls set up correctly (i.e. he looks at where the mouse is and transforms appropriately based on WSAD input), but I need some help with playing the right running animation based on which way the character is facing and moving. I've set up a 2D free form Cartesian in Mecanim - can anyone help point me in the right direction?
Here is my moving and rotating code:
     void UpdateControls()
         {
             _moveInput = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
             _moveDir = Camera.main.transform.TransformDirection(_moveInput);
             _moveDir.y = 0;
      
             _r.velocity = _moveDir.normalized * _speed * Time.deltaTime;
      
      
         }
      
         void UpdatePlayerDirection()
         {
             Ray _ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             RaycastHit _hit;
      
             if (Physics.Raycast(_ray, out _hit, 1 << 8))
             {
                 Vector3 _mousePoint = new Vector3(_hit.point.x, 0, _hit.point.z);
                 _charTransform.LookAt(_mousePoint);
             }
         }
 
Many thanks
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                