Hello, For some reason the direction my character is running is sideways rather than forward. I think I created it on the wrong axis in Blender and keyed all the animations to that. How do I fix this? Is there a fix in Unity? Code (csharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Player : MonoBehaviour { private CharacterController controller; private Animator anim; private Vector3 moveDirection = Vector3.zero; public float gravity = 20.0f; public float jumpForce = 10.0f; public float speed = 50.0f; public float turnSpeed = 50f; public GameObject runFaceVar; public GameObject jumpFaceVar; public GameObject idleFaceVar; // Start is called before the first frame update void Start() { controller = GetComponent<CharacterController>(); anim = gameObject.GetComponentInChildren<Animator>(); runFaceVar = GameObject.Find("/Lego_DrWho_IdleAnimation_noscrewdriver/Armature/Root/Spine 1/Spine 2/Neck/Head/Geo_Face.Run"); jumpFaceVar = GameObject.Find("/Lego_DrWho_IdleAnimation_noscrewdriver/Armature/Root/Spine 1/Spine 2/Neck/Head/Geo_Face.Jump"); idleFaceVar = GameObject.Find("/Lego_DrWho_IdleAnimation_noscrewdriver/Armature/Root/Spine 1/Spine 2/Neck/Head/Geo_Face.Idle"); } // Update is called once per frame void Update() { if (controller.isGrounded && Input.GetKey("up")) { anim.SetInteger("AnimPar", 1); moveDirection = transform.forward * Input.GetAxis("Vertical") * speed; float turn = Input.GetAxis("Horizontal"); //we want to turn around the y axis so we'll do that below transform.Rotate(0, turn * turnSpeed * Time.deltaTime, 0); runFaceVar.SetActive(true); idleFaceVar.SetActive(false); jumpFaceVar.SetActive(false); } else if (controller.isGrounded) { anim.SetInteger("AnimPar", 0); moveDirection = transform.forward * Input.GetAxis("Vertical") * 0; float turn = Input.GetAxis("Horizontal"); //we want to turn around the y axis so we'll do that below transform.Rotate(0, turn * turnSpeed * Time.deltaTime, 0); runFaceVar.SetActive(false); idleFaceVar.SetActive(true); jumpFaceVar.SetActive(false); } if (Input.GetButton("Jump") && controller.isGrounded) { anim.SetInteger("AnimPar", 2); moveDirection.y = jumpForce; runFaceVar.SetActive(false); idleFaceVar.SetActive(false); jumpFaceVar.SetActive(true); } controller.Move(moveDirection * Time.deltaTime); moveDirection.y -= gravity * Time.deltaTime; } }
Try adding Debug.Log statements throughout your code, it'll show you which parts are working and which aren't
That's the thing, it appears to be working. The character is moving, it's just not moving the correct direction. I even changed it to transform.right (to get it on the red axis) and now it runs backwards. (still facing the camera but moving away from it). This was one of the messages that came up with the debug: (2.3, 0.0, -5.5) UnityEngine.Debug:Log(Object) Player:Update() (at Assets/Lego Scripts/Player.cs:39)