Advertisement
jamieTheCoder

GridCharacterPathfinder3DWTurns

Nov 9th, 2022
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using MoreMountains.TopDownEngine;
  5.  
  6. public class GridCharacterPathfinder3DWTurns : GridCharacterPathfinder3D
  7. {
  8.     CharacterGridMovement characterGridMovment;
  9.    
  10.     protected override void Awake()
  11.     {
  12.         base.Awake();
  13.         characterGridMovment = GetComponent<CharacterGridMovement>();
  14.     }
  15.  
  16.     protected override void MoveController()
  17.     {
  18.                 if (Target == null || NextWaypointIndex <= 0)
  19.             characterGridMovment.SetMovement(Vector2.zero);
  20.         else
  21.         {
  22.             _direction = Waypoints[NextWaypointIndex] - transform.position;
  23.             if (Mathf.Abs(_direction.x) > Mathf.Abs(_direction.z))
  24.             {
  25.                 _newMovement.x = _direction.x;
  26.                 _newMovement.y = 0;
  27.             }
  28.             else
  29.             {
  30.                 _newMovement.x = 0;
  31.                 _newMovement.y = _direction.z;
  32.             }
  33.             //x = negative we move left
  34.             //x = positive we move right
  35.             //y = negative we move down
  36.             //y = positive we move up
  37.             if(_newMovement.x <0f)
  38.             {
  39.                 characterGridMovment.LeftOneCell();
  40.                 waitTillNextTurn();
  41.             }else
  42.             if(_newMovement.x > 0f)
  43.             {
  44.                 characterGridMovment.RightOneCell();
  45.                 waitTillNextTurn();
  46.             }
  47.             if(_newMovement.y <0f)
  48.             {
  49.                 characterGridMovment.DownOneCell();
  50.                 waitTillNextTurn();
  51.             }else
  52.             if(_newMovement.y>0f)
  53.             {
  54.                 characterGridMovment.UpOneCell();
  55.                 waitTillNextTurn();
  56.             }
  57.             //characterGridMovment.SetMovement(_newMovement);
  58.         }
  59.     }
  60.     private void waitTillNextTurn()
  61.     {
  62.        
  63.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement