Player movement script issue

Hello world!

Having a small issue and as im a very novice coder I am positive its in my script. I have written a bare bones script to use Rigidbody for character movement. Now that im trying to set up animation I have found that even when not pressing WASD to move my character its speed is still going up. The model will be completely still but the speed increases. Do I need to change something in this script?

Possibly but first you have to figure out what.

Steps:

  1. figure out what causes the animation
  2. identify all the variables / quantities involved
  3. use Debug.Log() to track down where it’s going wrong!
  4. PROFIT!

How are you moving the character? With a character controller? (Because I don’t see any WASD Input code).
Also, I think any Input code should go into Update() instead of FixedUpdate().

I usually have a bool (isMove) to manage the start and stopping of the movement. Regarding the animation, you’ll have to tell Unity to play and stop the animation. Something like this: (Untested)

private Animator anim;
private Rigidbody rb;

private void Start()
{
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody>();
}


private void Update()
{
if(Input.GetKey(KeyCode.D))
{

isMove = true;

}

}


private void FixedUpdate()
{

if(isMove)
{
anim.SetBool("isWalk", true);
//move rigidbody with MovePosition, velocity, or AddForce)
}
else
{

anim.SetBool("isWalk", false);
}

}

I have no idea if this was helpful, but I didn’t understand fully what you meant. Hopefully it was :stuck_out_tongue: