Hi All,
I hope this is the appropriate place to ask for help on this, I’ve about pulled my hair out.
I’m putting together a 2D Android tower-defense type game in 4.6.6f2 where the enemies are spawned (instantiated by prefab) on the right side of the screen and move to the left. I had everything working, just looked pretty basic, so I 'm going back and replacing a lot of the placeholder graphics.
I use a public float currentSpeed to set the enemy speed so I can dial in the speed where the feet aren’t slipping, but no matter what I do I can’t get my new enemy to move unless I hit Play, then go to the Animator component in the inspector and toggle Apply Root Motion. It doesn’t matter if I start with it unchecked or checked, my character won’t start moving until I’ve toggled that to whatever value it ISN"T while the game is running. I’ve tried toggling it programattically in my Start() but that doesn’t have the same result, I still need to either turn it off or on in the inspector while it is playing. All other enemies work without having to toggle that value (and all enemies share this script).
All enemies have a Rigidbody2D (set to isKinematic), a BoxCollider2D (isTrigger true), and are moved using my attacker script Update which looks like this:
void Update ()
{
// Checking to see if my values equal zero somewhere
Debug.Log ("V3:" + Vector3.left + " CS:" + currentSpeed + " dT:" + Time.deltaTime);
Debug.Log ("Total:" + (Vector3.left * currentSpeed * Time.deltaTime).ToString("F5"));
transform.Translate (Vector3.left * currentSpeed * Time.deltaTime);
if (!currentTarget)
{
anim.SetBool("isAttacking", false);
}
}
It almost seems to be something with the Animator component – I took an older enemy I’d made and started swapping out the sprites and components one at a time to see where it failed. Once i put the animator controller in, it stops moving left during the animation. The animation controller is very simple – has an isAttacking boolean and a default state of Walking with the walk animation. Normally I use a SetSpeed animation event once I’ve dialed in the speed from the public float, but at this time it is disabled so I can just pull from the float. While running I can tell that my Vector3.left * currentSpeed * Time.deltaTime is definitely not coming out to zero (though it is a small number, the actual Vector3 value is like (-0.00674, 0.00000, 0.00000).
Another odd issue is that I cannot put a check in the ‘isAttacking’ animator bool while running the game. All other enemies allow me to check that while running to make sure my attack animation look okay – but on this one enemy I can’t check it. Not like it checks and then unchecks, I literally cannot put a checkmark in the isAttacking bool to set it to true either through the animator window or through code. I have removed and recreated the Animator component and controller a couple times now, no change.
Any suggestions?