its either because i’ve wrote the code wrong because i’m new or not ticked a setting in the animation tree but when i move my character forward it will randomly get stuck in a forward loop and the animation will stay too, its like it thinks the keys still held down, only way to fix it while in game is to spam w, i’ve made sure the condition works to change the animation, the animation transitions has exit time boxes are unticked, the weird thing is when i changed Update to FIxedUpdate it happens much less, could it also be my crappy pc, codes here, ask me for screenshots not sure what to give ya.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Claytoncont : MonoBehaviour
{
public float speed = 4;
public float rotSpeed = 80;
float rot = 0f;
public float gravity = 8;
Vector3 moveDir = Vector3.zero;
CharacterController controller;
Animator anim;
void Start()
{
controller = GetComponent();
anim = GetComponent();
}
void FixedUpdate()
{
if (controller.isGrounded)
{
if (Input.GetKey(KeyCode.W))
{
anim.SetInteger(“condition”, 1);
moveDir = new Vector3(0, 0, 1);
moveDir *= speed;
moveDir = transform.TransformDirection(moveDir);
}
if (Input.GetKeyUp(KeyCode.W))
{
moveDir = new Vector3(0, 0, 0);
anim.SetInteger(“condition”, 0);
}
}
rot += Input.GetAxis(“Horizontal”) * rotSpeed * Time.deltaTime;
transform.eulerAngles = new Vector3(0, rot, 0);
moveDir.y -= gravity * Time.deltaTime;
controller.Move(moveDir * Time.deltaTime);
}
}