Animation Won't Loop (But others will)
As stated in the title, I just simply can't get my animation to loop (but others will). Basically, I'm very new to unity and I'm trying to learn unity to create my first game, so I have to start with the character. After a few hours of research and following some tutorials, I think I got a pretty good setup for my character. The only thing is, I want my character to be able to strafe left and right and whenever he strafes left, he just stays in the final frame. I have already looked up many many solutions to no prevail and I have also checked that both, "Loop Time" and "Loop Pose" are both checked on. As I said, I am new to Unity so this is my first script that I am using so please don't judge too hard (some code is directly off of tutorials while some aren't).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Controller : MonoBehaviour {
public float runSpeed = 2;
public float walkSpeed = 10;
public float rotateSpeed = 0.5f;
public float jumpSpeed = 6;
public float gravity = 20f;
private Vector3 moveDirection = Vector3.zero;
private CharacterController controller;
private Animator animator;
// Use this for initialization
void Start () {
controller = GetComponent<CharacterController>();
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
bool running = Input.GetKey(KeyCode.LeftShift);
if (running)
{
moveDirection *= runSpeed;
}
else {
moveDirection *= walkSpeed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
bool walkingForward = Input.GetKey("w");
float animationForward = ((walkingForward) ? 1 : 0);
animator.SetFloat("Input Z", animationForward);
bool strafeLeft = Input.GetKey("a");
float animationLeft = ((strafeLeft) ? 1 : 0);
animator.SetFloat("Input X", animationLeft);
if (!walkingForward && !strafeLeft)
{
animator.SetFloat("Input X", 0);
animator.SetFloat("Input Z", 0);
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612120537im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Animation and Stop Moving Won't Work? 1 Answer
How to get perfect position animation with root motion? 1 Answer
Character not moving off one spot 0 Answers
prevent animation loop. 0 Answers