- Home /
Archer Mecanim Animation - Not lining up correctly when movement is applied
Hi All,
Have an issue with mecanim and animations. to make it easy, I recorded and posted to Youtube here: https://www.youtube.com/watch?v=yuPWLhM7YPw the actual problem is shown @44seconds
Basically the archer mask does not line up with the archer aiming pivot, and cannot seem to work this problem out even after trying quite a few things. Most of the setup I believe I show in the video, and the script responsible for movement and aiming is:
using UnityEngine;
using System.Collections;
/// <summary>
/// Player animations.
/// This script is attached to the Player. It controls the players animations.
///
/// This script access the ArrowAimingRayAnimation Script. It updates the boolean aimingBeam.
/// </summary>
public class PlayerAnimations : MonoBehaviour {
//Variables Start
Animator anim;
public float speed = 6.0f;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
private CharacterController controller;
private ArrowAimingRayAnimation ArrowAimScript;
//Variables End
// public float headingAngle=0.0f;
//Variables End
// Use this for initialization
void Start ()
{
if(networkView.isMine == true)
{
anim = GetComponentInChildren<Animator>();
controller = GetComponent<CharacterController>();
ArrowAimScript = GetComponentInChildren<ArrowAimingRayAnimation>();
}
else
{
enabled = false;
}
}
// Update is called once per frame
void Update ()
{
// this gives you more control over the rotation around the look axis if needed
var direction = new Vector3(Input.GetAxis ("Horizontal Right Stick"), 0, -Input.GetAxis ("Vertical Right Stick") );
var rotation = Quaternion.LookRotation(direction, Vector3.up);
if(direction.magnitude > 0.3f)
transform.rotation = rotation;
// Debug.Log (rotation.eulerAngles.y);
float v = Input.GetAxis ("Vertical");
float h = Input.GetAxis ("Horizontal");
//Check if there is movement input. If input exists then run code to move the player.
if (h!=0 || v!=0)
{
//This controls the movement of the player
if (controller.isGrounded)
{
// We are grounded, so recalculate move direction directly from axes
moveDirection = new Vector3(h, 0, v);
moveDirection *= speed;
}
// Move the controller
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
// Get a copy of your forward vector
Vector3 forward = transform.forward;
// Zero out the y component of your forward vector to only get the direction in the X,Z plane
forward.y = 0;
float headingAngle = Quaternion.LookRotation(forward).eulerAngles.y;
var tempMoveDirection = Quaternion.LookRotation(moveDirection,Vector3.forward).eulerAngles.y;
anim.SetFloat("direction", -1*(headingAngle - tempMoveDirection));
anim.SetBool("movementInput", true);
}
else
{
anim.SetBool("movementInput",false);
}
//Checks to see if About to shoot. (Pulling Right Trigger)
if (Input.GetAxis ("FireWeapon") < -0.1f)
{
anim.SetBool("aiming", true);
ArrowAimScript.aimingBeam = true;
}
else
{
anim.SetBool("aiming",false);
ArrowAimScript.aimingBeam = false;
}
}
}
Any help would be grateful for this one as I am losing hair over this issue and all out of ideas.
Answer by Grieve_physics · Aug 16, 2014 at 02:26 AM
For those with a similar issue.
It was found that this problem is caused by the limitations within the Unity Mecanim controls. I had to get custom animations built, with no root animations and set up a secondary walk cycle with the bow.
It is doable with certain assets available from the Asset Store, but they are not default with mecanim.
*Credit to Props for solution to this one.
Your answer
Follow this Question
Related Questions
Looking for Unity 5 tutorials for perfect 3rdperson Character Movement 0 Answers
click to move workig script!! but pls help with rotation!! :( 1 Answer
How to make a RigidBody not go into ground when tilted foward? 2 Answers
Multiple movement modes in mecanim 0 Answers
Undesirable character flipping 0 Answers