private void FixedUpdate() { var vertical = InputGetAxis("Vertical"); var horizontal = -InputGetAxis("Horizontal"); var movement = new Vector3(vertical, 0, horizontal); IsoTransform.Translate(movement * Time.deltaTime * Speed); }
public void Update() { if (move) { Vector3 direction = Vector3.ClampMagnitude(new Vector3(target.x - isoTransform.Position.x, 0, target.z - isoTransform.Position.z), 1f); isoTransform.Translate(direction * speed * Time.deltaTime); if (Vector3.Distance(isoTransform.Position, target) < 0.1) { move = false; foreach (Animator animator in animators) { animator.SetFloat("Speed", 0); } } } }
void Update() { //translate on isotransform _isoTransform.Translate(new Vector3(Input.GetAxis("Vertical"), 0, -Input.GetAxis("Horizontal")) * Time.deltaTime * Speed); }
public IEnumerator MoveClick(GameObject clickedGo) { calcComplete = false; Debug.Log("Coroutine started."); Debug.Log("Clicked GO: " + clickedGo.name); List <GridInfo> newList = gameHandler.activeChar.movable; GridInfo c = newList.Find(x => x.go == clickedGo); activePlayerIsoTransform = gameHandler.activeChar.go.GetComponent <IsoTransform>(); playerAnim = gameHandler.activeChar.go.GetComponent <Animator>(); originalCharPos = activePlayerIsoTransform.Position; origin = Grid.Find(x => x.isoPos.x == originalCharPos.x && x.isoPos.z == originalCharPos.z); lastClicked = clickedGo; //for (int i = 0; i < c.path.Count; i++) Debug.Log("The " + i + " element of cPath is " + c.path[i]); //List<GridInfo> alts = bList.FindAll(x => x.go == c.go && x.path.Count == c.path.Count); //for(int n = 0; n < alts.Count; n++) //{ // Debug.Log("The " + n + " altPath has the following directions:"); // for (int i = 0; i < alts[n].path.Count; i++) Debug.Log("The " + i + " element of the " + n + " Path is " + alts[n].path[i]); //} foreach (GridInfo g in newList) { if (g != c) { g.go.SetActive(false); } } Vector3 v = new Vector3(0, 0, 0); Vector3 newPos = new Vector3(0, 0, 0); Vector3 roundPos = new Vector3(0, 0, 0); //float startTime = 0; playerAnim.SetBool("isWalking", true); for (int i = 0; i < c.path.Count; i++) { Debug.Log(c.path[i]); switch (c.path[i]) { case 3: playerAnim.SetBool("directionUp", true); playerAnim.SetBool("directionLeft", true); v = new Vector3(0, 0, 1); //Debug.Log("West"); break; case 0: playerAnim.SetBool("directionUp", true); playerAnim.SetBool("directionLeft", false); v = new Vector3(1, 0, 0); //Debug.Log("North"); break; case 1: playerAnim.SetBool("directionUp", false); playerAnim.SetBool("directionLeft", false); v = new Vector3(0, 0, -1); //Debug.Log("East"); break; case 2: playerAnim.SetBool("directionUp", false); playerAnim.SetBool("directionLeft", true); v = new Vector3(-1, 0, 0); //Debug.Log("South"); break; } if (i >= 1 && c.path[i - 1] != c.path[i]) { yield return(new WaitForSeconds(0.3f)); } if (i == c.path.Count - 1) { c.go.GetComponent <SpriteRenderer>().enabled = false; } //startTime = Time.time; //Debug.Log(newPos); if (c.pathDif[i] == 0) { newPos = activePlayerIsoTransform.Position + v; while (roundPos != newPos) { activePlayerIsoTransform.Translate(v * walkSpeed); roundPos = new Vector3(Mathf.Round(activePlayerIsoTransform.Position.x * 100) / 100, activePlayerIsoTransform.Position.y, Mathf.Round(activePlayerIsoTransform.Position.z * 100) / 100); yield return(null); } activePlayerIsoTransform.Position = newPos; //yield return new WaitUntil(() => activePlayer.GetComponent<IsoTransform>().Position == newPos); } else { newPos = activePlayerIsoTransform.Position + v * 0.4f; while (roundPos != newPos) { activePlayerIsoTransform.Translate(v * walkSpeed); roundPos = new Vector3(Mathf.Round(activePlayerIsoTransform.Position.x * 100) / 100, activePlayerIsoTransform.Position.y, Mathf.Round(activePlayerIsoTransform.Position.z * 100) / 100); yield return(null); } activePlayerIsoTransform.Position = newPos; newPos = activePlayerIsoTransform.Position + v * 0.2f + new Vector3(0, c.pathDif[i], 0); while (roundPos != newPos) { activePlayerIsoTransform.Translate((v * 0.2f + new Vector3(0, c.pathDif[i], 0)) * walkSpeed); roundPos = new Vector3(Mathf.Round(activePlayerIsoTransform.Position.x * 100) / 100, Mathf.Round(activePlayerIsoTransform.Position.y * 100) / 100, Mathf.Round(activePlayerIsoTransform.Position.z * 100) / 100); yield return(null); } activePlayerIsoTransform.GetComponent <IsoTransform>().Position = newPos; newPos = activePlayerIsoTransform.Position + v * 0.4f; while (roundPos != newPos) { activePlayerIsoTransform.Translate(v * walkSpeed); roundPos = new Vector3(Mathf.Round(activePlayerIsoTransform.Position.x * 100) / 100, activePlayerIsoTransform.Position.y, Mathf.Round(activePlayerIsoTransform.Position.z * 100) / 100); yield return(null); } activePlayerIsoTransform.Position = newPos; } //Debug.Log("Finished this partial movement."); } playerAnim.SetBool("isWalking", false); c.go.GetComponent <SpriteRenderer>().enabled = true; c.go.SetActive(false); moveComplete = true; gameHandler.canBeUndone = true; gameHandler.canBeCancelled = false; gameHandler.actionButton[0].GetComponent <TextMeshProUGUI>().text = "undo"; gameHandler.ButtonStateCheck(); yield return(new WaitUntil(() => gameHandler.movementIsPerm)); origin.pop = 0; var postPos = Grid.Find(x => x.go == clickedGo); postPos.pop = (gg.Contains(gameHandler.activeChar.go)) ? (sbyte)1 : (sbyte)-1; calcComplete = true; }