- Home /
The question is answered, right answer was accepted
Animator parameters can't be changed by code and won't make animations transition when active
Hi I am trying to get a idle animation to transition into a running animation but after two tutorials the parameters won't change or work when manually changed. For the current parameter I'm trying to use I am using a bool: if (rb.velocity.magnitude > 0) { // Player is moving animator.SetBool("isRunning", true); }
If you have the answer to this please leave a comment, I must of missed something very obvious.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float moveSpeed = 5f;
public Rigidbody2D rb;
Vector2 movement;
public Animator animator;
float mx;
// Update is called once per frame
void Update()
{
//Input
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
if (Input.GetKeyDown("a"))
{
transform.localScale = new Vector3(-1f, 1f, 1f);
}
if (Input.GetKeyDown("d"))
{
transform.localScale = new Vector3(1f, 1f, 1f);
}
/* Fix this. This code below which seems to be correct but does not change the animator perameters
and the perameters themselfs don't make the animation transition. */
if (rb.velocity.magnitude > 0)
{
// Player is moving
animator.SetBool("isRunning", true);
}
//animator.SetFloat("Speed");
/*
if (Mathf.Abs(mx) > 0.05)
{
anim.SetBool("isRunning", true);
}
else
{
anim.SetBool("isRunning", false);
}
if ("isRunning" = true)
{
}*/
}
private void FixedUpdate()
{
//Movement
rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
}
}
try using a Debug.Log at the line where you set the parameter to true to check if it actually does...if it does....check that you don't have exit time enabled on the transition in the animation controller and that the parameter is properly setup
Follow this Question
Related Questions
Animator.SetBool doesn't work first time 1 Answer
Why my animation transition glitches? 0 Answers
Root motion accuracy issue 0 Answers
Altered Mecanim parameters reset the current state back to the default state. 0 Answers
The "+" icon in Parameters within the Animator is greyed out, what am I doing wrong? 2 Answers