- Home /
 
Character Not Moving RPG Game
Hi all,
I have been not working on this project for a long time, but I remember the last time I was, the character was moving. Now, when I try to move, the animator works, but the movement (or the translation of the character and camera) are not working. What I tried: - Fixing the script's 2D vector, which seemed to be fine, as shown in the code. - Fix Input from Edit > Project Settings, which only had one error, where the vertical was assigned to the x-axis, but I did fix it and nothing has happened. The negative alts are assigned correctly to WASD. - Check Animator Apply Root Motion option, which is not ticked.
Following is the script of the movement that I have attached to the RPG Character. The game is sort of Pokemon-like:
 using UnityEngine;
 using System.Collections;
 using System.Text.RegularExpressions;
 
 public class Movement : MonoBehaviour
 {
     //GOING TO DO MAJOR CHANGES STARTING NOW!
     public Vector2 speed = new Vector2(50, 50);
     public string TagName;
     private treeHeal th;
     public bool canIMove;
     private Vector2 movement;
     public AudioSource backgroundAudio;
     public AudioSource fireStageBackgroundAudio;
     public AudioSource getHealed;
     public AudioSource walkingSound1;
     private Animator animator;
     private bool wisDown = false;
     private bool sisDown = false;
     private bool aisDown = false;
     private bool disDown = false;
     private bool walkingSound;
     private int counter = 0;
     #region for fire monster king checking his death to toggle this
     //In here, I have done the assignment of death of the fire monster, what I need to do now is not be able to pass another stage if the fire boss hasn't died
     private bool FireSkeletonMonsterBossDeathRecord = false;
     private MonsterHealthScript checkDeath;
     #endregion
     public bool fireStageTrigger;
     void Start(){
         canIMove = true;
         if (fireStageTrigger == true) {
             fireStageBackgroundAudio.Play ();
         } else {
             backgroundAudio.Play ();
         }
 
     }
 
     void Update()
     {
 
         // 3 - Retrieve axis information
         //Previously, it was GetAxis(), however that adds interia
         //We removed GetAxis and replaced it with GetAxisRaw to remove the inertia
         float inputX = Input.GetAxisRaw ("Horizontal");
         float inputY = Input.GetAxisRaw ("Vertical");
         // 4 - Movement per direction
         if (checkDeath.enemyhp <= 0) {
             FireSkeletonMonsterBossDeathRecord = true;
         }
         getCanIMove ();
         if (canIMove == false) {
             if (fireStageTrigger == true) {
                 fireStageBackgroundAudio.Stop ();
             } else {
                 backgroundAudio.Stop ();
             }
         }
             movement = new Vector2 (
                 speed.x * inputX,
                 speed.y * inputY);
         if (Input.GetKeyDown ("w")) {
             walkingSound1.loop = true;
             walkingSound1.Play();
             wisDown = true;
             disDown = false;
             aisDown = false;
             sisDown = false;
 
         }
         else if (Input.GetKeyDown ("d")) {
             walkingSound1.loop = true;
             walkingSound1.Play();
             wisDown = false;
             disDown = true;
             aisDown = false;
             sisDown = false;
         }
 
         else if (Input.GetKeyDown ("s")) {
             walkingSound1.loop = true;
             walkingSound1.Play();
             wisDown = false;
             disDown = false;
             aisDown = false;
             sisDown = true;
         }
         else if (Input.GetKeyDown ("a")) {
             walkingSound1.loop = true;
             walkingSound1.Play();
             walkingSound = true;
             wisDown = false;
             disDown = false;
             aisDown = true;
             sisDown = false;
         }
         else if (Input.GetKeyUp ("w")) {
             walkingSound1.loop = false;
         }
         else if (Input.GetKeyUp ("a")) {
             walkingSound1.loop = false;
         }
         else if (Input.GetKeyUp ("s")) {
             walkingSound1.loop = false;
         }
         else if (Input.GetKeyUp ("d")) {
             walkingSound1.loop = false;
         }
     
 
 
     }
     public bool getCanIMove(){
         return canIMove;
 
     }
     public IEnumerator treeWaiterFunction(){
         yield return new WaitForSeconds (2.5f);
         canIMove = true;
         if (fireStageTrigger == true) {
             fireStageBackgroundAudio.Play ();
         } else {
             backgroundAudio.Play ();
         }
     }
 
     void OnTriggerEnter2D(Collider2D otherCollider){
 
         if (Regex.IsMatch (otherCollider.tag, "Monster", RegexOptions.IgnoreCase)) {
             canIMove = false;
             if (fireStageTrigger == true) {
                 fireStageBackgroundAudio.Stop ();
             } else {
                 backgroundAudio.Stop ();
             }
 
         } else if (otherCollider.tag == "Tree") {
             canIMove = false;
 
             treeHeal myTree = otherCollider.gameObject.GetComponent<treeHeal> ();
             if (fireStageTrigger == true) {
                 fireStageBackgroundAudio.Stop ();
             } else {
                 backgroundAudio.Stop ();
             }
             myTree.healParticle.Play ();
             myTree.treeTheme.Play ();
             gameObject.GetComponent<PlayerHealthScript> ().playerhp = 100;
             StartCoroutine (treeWaiterFunction ());
 
         } else if (otherCollider.tag == "NPC") {
             canIMove = false;
 
             
         } else if (otherCollider.tag == "FireSkeletonMonsterBoss") {
             checkDeath = otherCollider.gameObject.GetComponent<MonsterHealthScript>();
         }
             
         
 
         else {
             canIMove = true;
         }
 
     }
     void FixedUpdate()
     {
         // 5 - Move the game object
         if (canIMove == true) {
             GetComponent<Rigidbody2D> ().velocity = movement;
         } else if (canIMove == false) {
         
             Vector2 temp = new Vector2(0,0);
             GetComponent<Rigidbody2D>().velocity = temp;
         }
     
     }
 }
 
               It is really bugging me. I wish I could fix it. Think it could be a unity thing?
Your answer