private void movement() { float inputX = Input.GetAxis("Horizontal"); float inputY = Input.GetAxis("Vertical"); Vector2 currentPos = rbody.position; Vector2 inputVector = new Vector2(inputX, inputY); //inputVector = Vector2.ClampMagnitude(inputVector, 1); Vector2 movement = inputVector * speed; Vector2 newPos = currentPos + movement * Time.fixedDeltaTime; rbody.MovePosition(newPos); //Get Current Run and Current Idle CurrentRun = gameObject.GetComponent <DirectionMovement>().CurrentDir; currentIdle = gameObject.GetComponent <DirectionMovement>().lastIdle; //Play animations depends if the character moves or not if (currentPos.Equals(newPos)) { animator.Play(currentIdle.ToString()); } else { //Set Direction and play CurrentRun = CurrentViewFromCroshair(); //TODO - Need to Set new last idle animator.Play(CurrentRun.ToString()); } }
void Awake() { //Initial direction _lastIdle = RunDirections.IdleS; //Get initial position currentPos = new Vector2(transformCharacter.position.x, transformCharacter.position.y); newPos = new Vector2(transformCharacter.position.x, transformCharacter.position.y); }
//Methods to places weapon. protected virtual void UpdateWeaponPosition(Transform characterTransform, GameObject weaponObject, GameObject character, Transform transformWeaponContainer) { //TODO: I don't know why I put this here... O.o ? //Vector3 mousePos = Input.mousePosition; //mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); //Vector3 force = Vector2.ClampMagnitude(new Vector2((mousePos.x - transform.position.x), (mousePos.y - transform.position.y)), baseDistanceBullet); RunDirections rd = character.GetComponent <MovementPlayer>().CurrentRun; if (rd.Equals(RunDirections.RunE)) { SetWeaponVariables(0.15f, -0.1f, -1.0f, true, true, false); } if (rd.Equals(RunDirections.RunSE)) { SetWeaponVariables(0.15f, -0.15f, -1.0f, true, true, false); } else if (rd.Equals(RunDirections.RunW)) { SetWeaponVariables(-0.15f, -0.1f, -1.0f, false, true, true); } else if (rd.Equals(RunDirections.RunSW)) { SetWeaponVariables(-0.15f, -0.15f, -1.0f, false, true, true); } else if (rd.Equals(RunDirections.RunNE)) { SetWeaponVariables(0.13f, -0.055f, 0.10f, true, false, false); } else if (rd.Equals(RunDirections.RunNW)) { SetWeaponVariables(-0.13f, -0.055f, 0.10f, false, false, true); } else if (rd.Equals(RunDirections.RunS)) { SetWeaponVariables(0.10f, -0.12f, -1.0f, true, true, false); } else if (rd.Equals(RunDirections.RunN)) { SetWeaponVariables(0.12f, -0.070f, -1.0f, false, false, false); } WeaponPosition = new Vector3(characterTransform.position.x + CorrectionXWeaponPosition, characterTransform.position.y + CorrectionYWeaponPosition, CorrectionZWeaponPosition); }
//Check the currentView between the player and crossHair private RunDirections CurrentViewFromCroshair() { RunDirections currentView = RunDirections.RunS; var crossDir = crossHair.GetComponent <CrossHair>().CrossHairAngle(playerTransform.position); switch (crossDir) { case 0: currentView = RunDirections.RunS; break; case 1: currentView = RunDirections.RunSE; break; case 2: currentView = RunDirections.RunE; break; case 3: currentView = RunDirections.RunNE; break; case 4: currentView = RunDirections.RunN; break; case 5: currentView = RunDirections.RunNW; break; case 6: currentView = RunDirections.RunW; break; case 7: currentView = RunDirections.RunSW; break; } return(currentView); }
//Check current directión, current dirrection uses to check last dir too. private void checkDirection(Vector2 currentPos, Vector2 newPos) { if (newPos.x > currentPos.x && newPos.y == currentPos.y) { _currentDir = RunDirections.RunE; _lastIdle = RunDirections.IdleE; } else if (newPos.x < currentPos.x && newPos.y == currentPos.y) { _currentDir = RunDirections.RunW; _lastIdle = RunDirections.IdleW; } else if (newPos.x == currentPos.x && newPos.y > currentPos.y) { _currentDir = RunDirections.RunN; _lastIdle = RunDirections.IdleN; } else if (newPos.x == currentPos.x && newPos.y < currentPos.y) { _currentDir = RunDirections.RunS; _lastIdle = RunDirections.IdleS; } else if (newPos.x > currentPos.x && newPos.y > currentPos.y) { _currentDir = RunDirections.RunNE; _lastIdle = RunDirections.IdleNE; } else if (newPos.x < currentPos.x && newPos.y > currentPos.y) { _currentDir = RunDirections.RunNW; _lastIdle = RunDirections.IdleNW; } else if (newPos.x > currentPos.x && newPos.y < currentPos.y) { _currentDir = RunDirections.RunSE; _lastIdle = RunDirections.IdleSE; } else if (newPos.x < currentPos.x && newPos.y < currentPos.y) { _currentDir = RunDirections.RunSW; _lastIdle = RunDirections.IdleSW; } }
void SetRunState() { if (state == states.RUN) { if (rotationY > LimitRotationToAnm && runDirection != RunDirections.LEFT) { runDirection = RunDirections.LEFT; madRoller.Play("run_right"); } else if (rotationY < -LimitRotationToAnm && runDirection != RunDirections.RIGHT) { runDirection = RunDirections.RIGHT; madRoller.Play("run_left"); } else if (rotationY == 0 && runDirection != RunDirections.CENTER) { madRoller.Play("run"); runDirection = RunDirections.CENTER; } } }
/** * Pas parametres first movement */ private IEnumerator RunInControl(Animator playerAnim, SpriteRenderer key, RunDirections run, RunDirections idle, float time) { if (!panelControl.activeSelf) { yield break; } key.color = KeyCapPulsed; playerAnim.Play(run.ToString()); yield return(new WaitForSeconds(time)); if (!panelControl.activeSelf) { yield break; } key.color = KeyCapNoPulsed; playerAnim.Play(idle.ToString()); switch (knowWhatIsNext(run)) { case 1: StartCoroutine(RunInControl(playerW, keyW, RunDirections.RunN, RunDirections.IdleN, timeRun)); break; case 2: StartCoroutine(RunInControl(playerD, keyD, RunDirections.RunE, RunDirections.IdleE, timeRun)); break; case 3: StartCoroutine(RunInControl(playerS, keyS, RunDirections.RunS, RunDirections.IdleS, timeRun)); break; case 4: StartCoroutine(RunInControl(playerA, keyA, RunDirections.RunW, RunDirections.IdleW, timeRun)); break; } }
private int knowWhatIsNext(RunDirections run) { int next = 0; if (run.Equals(RunDirections.RunN)) { next = 2; } else if (run.Equals(RunDirections.RunE)) { next = 3; } else if (run.Equals(RunDirections.RunS)) { next = 4; } else if (run.Equals(RunDirections.RunW)) { next = 1; } return(next); }