I have the sprite animations done for idle, walk left, walk right, jump left, jump right. With bools set to facingRight, isWalking, isJumping connecting the animations. With the jumping connecting to any state. For the script i have this : Code (CSharp): using UnityEngine; using System.Collections; public class PlayerMove : MonoBehaviour { public float moveSpeed; public float jumpHeight; private bool isGrounded; // Update is called once per frame void Update() { Vector3 move = new Vector3(Input.GetAxis("Horizontal"), 0, 0); transform.position += move * moveSpeed * Time.deltaTime; if (Input.GetKeyDown("w") && isGrounded) { GetComponent<Rigidbody2D>().AddForce(new Vector2(0, jumpHeight), ForceMode2D.Force); GetComponent<Animator>().SetBool("isJumping", true); StartCoroutine(JumpAnim()); } if (move.x > 0 && isGrounded) { GetComponent<Animator>().SetBool("isWalking", true); GetComponent<Animator>().SetBool("facingRight", true); } if (move.x < 0 && isGrounded) { GetComponent<Animator>().SetBool("isWalking", true); GetComponent<Animator>().SetBool("facingRight", false); } if (move.x < 0) { GetComponent<Animator>().SetBool("facingRight", false); } else if (move.x > 0) { GetComponent<Animator>().SetBool("facingRight", true); } if (move.x == 0 || isGrounded == false && GetComponent<Animator>().GetBool("isJumping") == false) { GetComponent<Animator>().SetBool("isWalking", false); } } IEnumerator JumpAnim() { yield return new WaitForSeconds(0.333f); GetComponent<Animator>().SetBool("isJumping", false); } void OnTriggerEnter2D() { isGrounded = true; } void OnTriggerStay2D() { isGrounded = true; } void OnTriggerExit2D() { isGrounded = false; } } and i did add w as a key for jump in settings Now the character moves left and right. However the walking animations wont trigger and it does not jump at all. Could use some help.
is it possible its not finding the sprite grounded? i have the base of the level set up with a edge collider, and the main sprite has a box collider and rigid body
You arent using the OnTriggerEnter2D or OnTriggerStay2D properly. Code (CSharp): void OnTriggerEnter2D(Collider2D col) { if(col.gameObject.tag == "Ground") { isGrounded = true; } } Check that out or look at the documentation. You need to do the same for OnTriggerStay2D and Exit2D.
Did as stated and now getting a compiler error: UnityEditor.SceneView:ShowCompileErrorNotification() (at C:/buildslave/unity/build/Editor/Mono/SceneView/SceneView.cs:3398)
Well did you set up a tag called "Ground" or anything? And after setting up the tag did you assign it to the ground gameobjects? Mine was just an example.
ok reloaded into unity, to reload the project with that added in place of original. sprite still only moves left and right stuck in idle animation no jumping. In the animator tab i have the animations loaded correctly with bools going to each one for isWalking,facingRight,isJumping. In the preview the animations work great, just in the game window nothing changes from moving left and right with only the idle animation.
i believe so from idle to walk right has booles isWalking true and facingRight true. from idle to Jumping Right has booles isJumping true and facingRight true etc
Man, I wish i could help more but i am not sure. Try looking for typos or small things. That error you sent doesnt really explain much, Im sure someone else may know more but without more details on the error, I am afraid I am not sure.