You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

757 lines
28 KiB

5 years ago
5 years ago
5 years ago
5 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6. using Networking.Server;
  7. public class Character : MonoBehaviour
  8. {
  9. public enum Animation { Walk, Run, Jump, Sit, Attack, Hit }
  10. public string nextScene;
  11. Animator characterAnimator;
  12. public bool isTuteLevel = false;
  13. public bool inWater = false; //Am I in the water?
  14. public bool inPit = false; //Did I fall into a pit?
  15. public bool stuck = false; //Am I still stuck?
  16. public bool justMoved = false; //Was the logic block I just executed a move command?
  17. Vector3 death = new Vector3(-50, 0, 0);
  18. #region Inspector Fields
  19. [SerializeField]
  20. [Tooltip("Will move to this block at start, else will try and find a block below")]
  21. private Block _currentBlock;
  22. [SerializeField]
  23. [Tooltip("Layers to ignore when checking for blocks")]
  24. public LayerMask Ignore;
  25. [Tooltip("Current Inventory of the player")]
  26. public Inventory Inventory;
  27. public bool CloneInventoryOnStart = false;
  28. [Tooltip("How many lives to start out with")]
  29. public int lives = 3;
  30. [SerializeField]
  31. [Tooltip("Character to display")]
  32. private string CharacterModel = "Bear";
  33. [SerializeField]
  34. public ClientData ClientLink;
  35. [SerializeField]
  36. private TMPro.TextMeshPro BlockTitlePrefab;
  37. #endregion Inspector Fields
  38. #region Read Only
  39. public Block CurrentBlock { get { return _currentBlock; } }
  40. #endregion Read Only
  41. #region Unity Functions
  42. private void Start()
  43. {
  44. if (Inventory != null && CloneInventoryOnStart)
  45. Inventory = Inventory.Clone(Inventory);
  46. //If no starting block find one below it
  47. if (_currentBlock == null)
  48. Block.isBlockAtPosition(transform.position + Vector3.down / 2, 1, ~Ignore, out _currentBlock);
  49. //move to starting block
  50. transform.position = _currentBlock.VisualPosition;
  51. //get character string from player replace from "Bear"
  52. GameObject prefab = Resources.Load(CharacterModel) as GameObject;
  53. GameObject animal = Instantiate(prefab, this.gameObject.transform);
  54. characterAnimator = GetComponentInChildren<Animator>();
  55. }
  56. private void Update()
  57. {
  58. if(lives < 1)
  59. {
  60. this.transform.position = death;
  61. //this.enabled = false;
  62. //gameObject.SetActive(false);
  63. }
  64. }
  65. #endregion Unity Functions
  66. #region Class Implementation
  67. public void Initialise(Block startingBlock, Inventory inventory, string Character)
  68. {
  69. _currentBlock = startingBlock;
  70. Inventory = inventory;
  71. CharacterModel = Character;
  72. }
  73. public void DisplayBlock(LogicBlock block)
  74. {
  75. if (isTuteLevel == false)
  76. {
  77. if (BlockTitlePrefab == null)
  78. return;
  79. TMPro.TextMeshPro temp = Instantiate(BlockTitlePrefab.gameObject).GetComponent<TMPro.TextMeshPro>();
  80. temp.text = block.DisplayName;
  81. temp.color = ClientLink.Color;
  82. temp.transform.position = transform.position + (Vector3.one * 0.25f);
  83. temp.transform.rotation = Quaternion.LookRotation(temp.transform.position - Camera.main.transform.position);
  84. }
  85. }
  86. public IEnumerator MoveToBlock(Block target, Animation animation, float time)
  87. {
  88. float startTime = Time.time;
  89. Vector3 moveDirection = Vector3.ProjectOnPlane(target.position - _currentBlock.position, Vector3.up).normalized;
  90. _currentBlock.OnLeftByPlayer(this);
  91. System.Func<float, float> yFunction = null;
  92. if (animation == Animation.Jump)
  93. yFunction = (t) => Mathf.Sin((Mathf.PI * t));
  94. StartAnimation(animation, time);
  95. yield return StartCoroutine(LerpToBlock(target.VisualPosition, time * 0.8f, yFunction));
  96. _currentBlock= target;
  97. yield return StartCoroutine (_currentBlock.OnWalkedOnByPlayer(this,moveDirection));
  98. yield return new WaitForSeconds(time - (Time.time - startTime));
  99. StopAnimation(animation);
  100. }
  101. public IEnumerator RotateToDirection(Direction direction, Animation animation, float time, bool isLocal = true)
  102. {
  103. System.Func<float, float> yFunction = null;
  104. if (animation == Animation.Jump)
  105. yFunction = (t) => Mathf.Sin((Mathf.PI * t));
  106. Vector3 _endDir = isLocal ? direction.ToVector(transform) : direction.ToVector();
  107. StartAnimation(animation, time);
  108. yield return StartCoroutine(LerpToRotation(_endDir, time * 0.8f, yFunction));
  109. StopAnimation(animation);
  110. }
  111. private IEnumerator LerpToBlock(Vector3 target, float time, System.Func<float, float> heightOffset = null)
  112. {
  113. Vector3 _startPos = transform.position;
  114. Vector3 _endPos = target;
  115. Vector3 _newPos;
  116. float elapsedTime = 0;
  117. while (elapsedTime / time < 1)
  118. {
  119. _newPos = Vector3.Lerp(_startPos, _endPos, (elapsedTime / time));
  120. if (heightOffset != null)
  121. _newPos.y += heightOffset(elapsedTime / time);
  122. transform.position = _newPos;
  123. yield return new WaitForEndOfFrame();
  124. elapsedTime += Time.deltaTime;
  125. }
  126. _newPos = _endPos;
  127. if (heightOffset != null)
  128. _newPos.y += heightOffset(1);
  129. transform.position = _newPos;
  130. }
  131. private IEnumerator LerpToRotation(Vector3 target, float time, System.Func<float, float> heightOffset = null)
  132. {
  133. Vector3 _startDir = transform.forward;
  134. Vector3 _endDir = target;
  135. Vector3 _startPos = transform.position;
  136. float elapsedTime = 0;
  137. while (elapsedTime / time < 1)
  138. {
  139. transform.forward = Vector3.Slerp(_startDir, _endDir, (elapsedTime / time));
  140. if (heightOffset != null)
  141. transform.position = _startPos + Vector3.up * heightOffset(elapsedTime / time);
  142. yield return new WaitForEndOfFrame();
  143. elapsedTime += Time.deltaTime;
  144. }
  145. transform.forward = target;
  146. if (heightOffset != null)
  147. transform.position = _startPos + Vector3.up * heightOffset(1);
  148. }
  149. public IEnumerator AnimateToPosition(Vector3 position, Animation animation, float time)
  150. {
  151. System.Func<float, float> yFunction = null;
  152. if (animation == Animation.Jump)
  153. yFunction = (t) => Mathf.Sin((Mathf.PI * t));
  154. StartAnimation(animation, time);
  155. yield return StartCoroutine(LerpToBlock(position, time * 0.8f, yFunction));
  156. StopAnimation(animation);
  157. }
  158. public void StartAnimation(Animation animation,float speed = 1)
  159. {
  160. characterAnimator.SetFloat("AnimationSpeed", (1 / speed));
  161. switch (animation)
  162. {
  163. case Animation.Walk:
  164. characterAnimator.SetBool("isWalking", true);
  165. break;
  166. case Animation.Run:
  167. characterAnimator.SetBool("isRunning", true);
  168. break;
  169. case Animation.Sit:
  170. characterAnimator.SetBool("isSitting", true);
  171. break;
  172. case Animation.Jump:
  173. characterAnimator.SetTrigger("Jump");
  174. break;
  175. case Animation.Attack:
  176. characterAnimator.SetTrigger("Attack");
  177. break;
  178. case Animation.Hit:
  179. characterAnimator.SetTrigger("Hit");
  180. break;
  181. default:
  182. break;
  183. }
  184. }
  185. public void StopAnimation(Animation animation)
  186. {
  187. characterAnimator.SetFloat("AnimationSpeed", 1f);
  188. switch (animation)
  189. {
  190. case Animation.Walk:
  191. characterAnimator.SetBool("isWalking", false);
  192. break;
  193. case Animation.Run:
  194. characterAnimator.SetBool("isRunning", false);
  195. break;
  196. case Animation.Sit:
  197. characterAnimator.SetBool("isSitting", false);
  198. break;
  199. }
  200. }
  201. public void respawnCharacter()
  202. {
  203. /* Will introduce more complex criteria for choosing where to respawn the player in future
  204. * For now: if the square one back (x =- 1) from the pit is walkable and unoccupied, then put them there
  205. * Otherwise, try the next square back, etc, until we find an available one
  206. */
  207. Block currentBlock = null;
  208. //We start from the position of our pit, at ground level
  209. Vector3 currentPos = new Vector3(this.transform.position.x, this.transform.position.y, this.transform.position.z);
  210. Debug.Log("Commencing respawn");
  211. //Hardcoding the number of iterations for now for simplicity, should change this later
  212. for (int i = 0; i < 100; i++)
  213. {
  214. //First we check one back
  215. currentPos.x -= 1;
  216. Debug.Log("currentPos = " + currentPos.x + ", " + currentPos.y + ", " + currentPos.z);
  217. if (Block.isBlockAtPosition(currentPos, 1, ~Ignore, out currentBlock)) //Does a block exist here?
  218. {
  219. Debug.Log("Block exists");
  220. if (currentBlock.isWalkable(~Ignore)) //If so, can we walk on it?
  221. {
  222. Debug.Log("Block is walkable");
  223. //Don't yet have a check for whether it's occupied
  224. break; //If it is, we stop here
  225. }
  226. }
  227. //If the block one back isn't an option, we check to the left and right
  228. currentPos.z += 1;
  229. Debug.Log("currentPos = " + currentPos.x + ", " + currentPos.y + ", " + currentPos.z);
  230. if (Block.isBlockAtPosition(currentPos, 1, ~Ignore, out currentBlock)) //Does a block exist here?
  231. {
  232. Debug.Log("Block exists");
  233. if (currentBlock.isWalkable(~Ignore)) //If so, can we walk on it?
  234. {
  235. Debug.Log("Block is walkable");
  236. //Don't yet have a check for whether it's occupied
  237. break; //If it is, we stop here
  238. }
  239. }
  240. currentPos.z -= 2;
  241. Debug.Log("currentPos = " + currentPos.x + ", " + currentPos.y + ", " + currentPos.z);
  242. if (Block.isBlockAtPosition(currentPos, 1, ~Ignore, out currentBlock)) //Does a block exist here?
  243. {
  244. Debug.Log("Block exists");
  245. if (currentBlock.isWalkable(~Ignore)) //If so, can we walk on it?
  246. {
  247. Debug.Log("Block is walkable");
  248. //Don't yet have a check for whether it's occupied
  249. break; //If it is, we stop here
  250. }
  251. }
  252. //If we've gotten this far and haven't found an available spot, we move back a row and try again
  253. currentPos.z += 1;
  254. }
  255. //Having found our target block, we move the character there
  256. if (currentBlock != null)
  257. {
  258. this.transform.position = currentBlock.VisualPosition;
  259. this.inPit = false;
  260. this._currentBlock = currentBlock;
  261. Debug.Log("Moved " + this.name + " to "
  262. + this.transform.position.x + ", "
  263. + this.transform.position.y + ", "
  264. + this.transform.position.z + ", "
  265. + " inPit = " + inPit);
  266. }
  267. else
  268. {
  269. Debug.Log("Failed to find anywhere to put " + this.name);
  270. }
  271. }
  272. /// <summary>
  273. /// Upon collision with a floating block, collect its
  274. /// Upon collision with the end portal, end of level
  275. /// </summary>
  276. /// <param name="other">name of collided object</param>
  277. void OnTriggerEnter(Collider other)
  278. {
  279. Collectable collectable = other.GetComponentInChildren<Collectable>();
  280. if (collectable != null)
  281. {
  282. collectable.OnCollect(this);
  283. }
  284. if (other.gameObject.name == "collect_sphere")
  285. {
  286. other.gameObject.SetActive(false);
  287. //player.collected +=1;
  288. }
  289. if (other.gameObject.name == "End Portal")
  290. {
  291. other.GetComponent<Collider>().enabled = false;
  292. SceneManager.LoadScene(nextScene);
  293. }
  294. }
  295. /// <summary>
  296. /// Rotates to point in specific direction based on current direction
  297. /// </summary>
  298. /// <param name="direction">Local direction to point</param>
  299. public void Rotate(Direction direction, float speed)
  300. {
  301. StartCoroutine(rotateCoroutine(direction, transform, speed, 0.15f));
  302. //transform.forward = direction.ToVector(transform);
  303. }
  304. public void RotateHalf(Direction direction, float speed)
  305. {
  306. StartCoroutine(rotateHalfCoroutine(direction, transform, speed, 0.15f));
  307. //transform.forward = direction.ToVector(transform);
  308. }
  309. /// <summary>
  310. /// Jumps in specefied direction, picks between Long Jump and Jumping up
  311. /// </summary>
  312. /// <param name="direction">Direction to Jump</param>
  313. public void Jump(Direction direction, float speed)
  314. {
  315. //if there is a block infront JumpUp else LongJump
  316. if (Block.isBlockAtPosition(_currentBlock.position + direction.ToVector(transform) + Vector3.up, 1, ~Ignore))
  317. JumpUp(direction, speed);
  318. else
  319. JumpLong(direction, speed);
  320. }
  321. #endregion Class Implementation
  322. #region Private Functions
  323. /// <summary>
  324. /// Jumps up obstacle of specific height. Jumps as high as possible
  325. /// </summary>
  326. /// <param name="direction">Direction of obstacle</param>
  327. /// <param name="height">max height</param>
  328. private void JumpUp(Direction direction, float speed, int height = 1)
  329. {
  330. //setting up variables
  331. Vector3 position; // position wanted
  332. Block hit; //output of block detection
  333. Block moveTo = _currentBlock; //block we'll actually move to
  334. //Check blocks in going up then move to the heighest walkable one
  335. for (int i = 0; i <= height; i++)
  336. {
  337. //next position up the tower
  338. position = _currentBlock.position + direction.ToVector(transform) + (Vector3.up * i);
  339. //if block is walkable set it to last known position
  340. if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore))
  341. moveTo = hit;
  342. }
  343. //set current block && move
  344. _currentBlock = moveTo;
  345. StartCoroutine(JumpCoroutine(_currentBlock, transform, speed, 0.5f));
  346. //transform.position = CurrentBlock.VisualPosition;
  347. }
  348. /// <summary>
  349. /// Long jumps forward a specified distance. Can Jump gaps. Stops at obstruction
  350. /// </summary>
  351. /// <param name="direction">Direction to Jump</param>
  352. /// <param name="Distance">Max distance</param>
  353. private void JumpLong(Direction direction, float speed, int Distance = 2)
  354. {
  355. //setting up variables
  356. Vector3 position; // position wanted
  357. Block hit; //output of block detection
  358. Block moveTo = _currentBlock; //block we'll actually move to
  359. //Check blocks in front until we hit an obstruction or went the distance
  360. for (int i = 1; i <= Distance; i++)
  361. {
  362. //Next position to MoveTo
  363. position = _currentBlock.position + (direction.ToVector(transform) * i);
  364. //if jump is obstructed, stop and go to last known block
  365. if (Block.isBlockAtPosition(position + Vector3.up, 1, ~Ignore))
  366. break;
  367. //If block at Position is walkable set it to last known position
  368. if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore))
  369. moveTo = hit;
  370. //else if block down one is walkable
  371. else if (Block.isBlockAtPosition(position + Vector3.down, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore))
  372. moveTo = hit;
  373. }//end for
  374. //Set Current Block and move
  375. _currentBlock = moveTo;
  376. StartCoroutine(JumpCoroutine(_currentBlock, transform, speed, 0.5f));
  377. //transform.position = CurrentBlock.VisualPosition;
  378. }
  379. #endregion Private Functions
  380. #region Depricated
  381. IEnumerator JumpCoroutine(Block Target, Transform Current, float time, float heightMax)
  382. {
  383. float elapsedTime = 0;
  384. Vector3 startPosition = Current.position;
  385. time *= 0.8f;
  386. characterAnimator.Play("Jump Inplace");
  387. yield return new WaitForSeconds(0.15f);
  388. while (elapsedTime < time)
  389. {
  390. transform.position = Vector3.Lerp(startPosition, Target.VisualPosition, (elapsedTime / time));
  391. //transform.position += yValue((elapsedTime / time), heightMax);
  392. yield return new WaitForEndOfFrame();
  393. elapsedTime += Time.deltaTime;
  394. }
  395. transform.position = Target.VisualPosition;
  396. }
  397. IEnumerator MoveCoroutine(Block Target, Transform Current, float time, float heightMax)
  398. {
  399. float elapsedTime = 0;
  400. Vector3 startPosition = Current.position;
  401. time *= 0.8f;
  402. characterAnimator.Play("Walk");
  403. yield return new WaitForSeconds(0.05f);
  404. while (elapsedTime < time)
  405. {
  406. transform.position = Vector3.Lerp(startPosition, Target.VisualPosition, (elapsedTime / time));
  407. yield return new WaitForEndOfFrame();
  408. elapsedTime += Time.deltaTime;
  409. }
  410. transform.position = Target.VisualPosition;
  411. }
  412. IEnumerator MoveConveyorForwardCoroutine(Block Target, Transform Current, float time, float heightMax)
  413. {
  414. float elapsedTime = 0;
  415. Vector3 startPosition = Current.position;
  416. Vector3 charEndPosition = new Vector3(Current.position.x + 1.0f, Current.position.y, Current.position.z);
  417. time *= 0.8f;
  418. yield return new WaitForSeconds(0.05f);
  419. while (elapsedTime < time)
  420. {
  421. Current.position = Vector3.Lerp(startPosition, charEndPosition, (elapsedTime / time));
  422. yield return new WaitForEndOfFrame();
  423. elapsedTime += Time.deltaTime;
  424. }
  425. Current.position = charEndPosition;
  426. }
  427. IEnumerator MoveConveyorBackwardCoroutine(Block Target, Transform Current, float time, float heightMax)
  428. {
  429. float elapsedTime = 0;
  430. Vector3 startPosition = Current.position;
  431. Vector3 charEndPosition = new Vector3(Current.position.x - 1.0f, Current.position.y, Current.position.z);
  432. time *= 0.8f;
  433. yield return new WaitForSeconds(0.05f);
  434. while (elapsedTime < time)
  435. {
  436. Current.position = Vector3.Lerp(startPosition, charEndPosition, (elapsedTime / time));
  437. yield return new WaitForEndOfFrame();
  438. elapsedTime += Time.deltaTime;
  439. }
  440. Current.position = charEndPosition;
  441. }
  442. IEnumerator MoveConveyorLeftCoroutine(Block Target, Transform Current, float time, float heightMax)
  443. {
  444. float elapsedTime = 0;
  445. Vector3 startPosition = Current.position;
  446. Vector3 charEndPosition = new Vector3(Current.position.x, Current.position.y, Current.position.z + 1.0f);
  447. time *= 0.8f;
  448. yield return new WaitForSeconds(0.05f);
  449. while (elapsedTime < time)
  450. {
  451. Current.position = Vector3.Lerp(startPosition, charEndPosition, (elapsedTime / time));
  452. yield return new WaitForEndOfFrame();
  453. elapsedTime += Time.deltaTime;
  454. }
  455. Current.position = charEndPosition;
  456. }
  457. IEnumerator MoveConveyorRightCoroutine(Block Target, Transform Current, float time, float heightMax)
  458. {
  459. float elapsedTime = 0;
  460. Vector3 startPosition = Current.position;
  461. Vector3 charEndPosition = new Vector3(Current.position.x, Current.position.y, Current.position.z - 1.0f);
  462. time *= 0.8f;
  463. yield return new WaitForSeconds(0.05f);
  464. while (elapsedTime < time)
  465. {
  466. Current.position = Vector3.Lerp(startPosition, charEndPosition, (elapsedTime / time));
  467. yield return new WaitForEndOfFrame();
  468. elapsedTime += Time.deltaTime;
  469. }
  470. Current.position = charEndPosition;
  471. }
  472. IEnumerator PushLeftCoroutine(Transform Current, float time)
  473. {
  474. float elapsedTime = 0;
  475. Vector3 startPosition = Current.transform.position;
  476. Vector3 endPosition = new Vector3(Current.position.x, Current.position.y, Current.position.z + 1.0f);
  477. time *= 0.8f;
  478. yield return new WaitForSeconds(0.05f);
  479. while (elapsedTime < time)
  480. {
  481. Current.position = Vector3.Lerp(startPosition, endPosition, (elapsedTime / time));
  482. yield return new WaitForEndOfFrame();
  483. elapsedTime += Time.deltaTime;
  484. }
  485. Current.position = endPosition;
  486. }
  487. IEnumerator PushRightCoroutine(Transform Current, float time)
  488. {
  489. float elapsedTime = 0;
  490. Vector3 startPosition = Current.transform.position;
  491. Vector3 endPosition = new Vector3(Current.position.x, Current.position.y, Current.position.z - 1.0f);
  492. time *= 0.8f;
  493. yield return new WaitForSeconds(0.05f);
  494. while (elapsedTime < time)
  495. {
  496. Current.position = Vector3.Lerp(startPosition, endPosition, (elapsedTime / time));
  497. yield return new WaitForEndOfFrame();
  498. elapsedTime += Time.deltaTime;
  499. }
  500. Current.position = endPosition;
  501. }
  502. IEnumerator MoveDownCoroutine(Block Target, Transform Current, float time, float heightMax)
  503. {
  504. float elapsedTime = 0;
  505. Vector3 startPosition = Current.position;
  506. time *= 0.8f;
  507. characterAnimator.Play("Walk");
  508. while (elapsedTime < time)
  509. {
  510. transform.position = Vector3.Lerp(startPosition, Target.VisualPosition, (elapsedTime / time));
  511. //transform.position += yValue((elapsedTime / time), heightMax);
  512. yield return new WaitForEndOfFrame();
  513. elapsedTime += Time.deltaTime;
  514. }
  515. transform.position = Target.VisualPosition;
  516. }
  517. IEnumerator rotateCoroutine(Direction direction, Transform Current, float time, float heightMax)
  518. {
  519. float elapsedTime = 0;
  520. time *= 0.8f;
  521. Vector3 endDirection = direction.ToVector(Current);
  522. Vector3 startDirection = Current.forward;
  523. while (elapsedTime < time)
  524. {
  525. characterAnimator.Play("Jump");
  526. transform.forward = Vector3.Slerp(startDirection, endDirection, (elapsedTime / time));
  527. yield return new WaitForEndOfFrame();
  528. elapsedTime += Time.deltaTime;
  529. }
  530. transform.forward = endDirection;
  531. }
  532. IEnumerator rotateHalfCoroutine(Direction direction, Transform Current, float time, float heightMax)
  533. {
  534. float elapsedTime = 0;
  535. time *= 0.8f;
  536. Vector3 endDirection = (direction.ToVector(Current) + Current.forward).normalized;
  537. Vector3 startDirection = Current.forward;
  538. while (elapsedTime < time)
  539. {
  540. characterAnimator.Play("Jump");
  541. transform.forward = Vector3.Slerp(startDirection, endDirection, (elapsedTime / time));
  542. yield return new WaitForEndOfFrame();
  543. elapsedTime += Time.deltaTime;
  544. }
  545. transform.forward = endDirection;
  546. }
  547. /// <summary>
  548. /// Moves one block in specefied direction, Can walk off obstacles
  549. /// </summary>
  550. /// <param name="direction">direction to walk</param>
  551. /// <remarks>Technically is same as JumpLong(1) but kept seperate to avoid confusion</remarks>
  552. public void Move(Direction direction, float speed)
  553. {
  554. //setting up variables
  555. Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted
  556. Block hit; //output of block detection
  557. Block moveTo = _currentBlock; //block we'll actually move to
  558. //if move is obstucted no where to move
  559. if (Block.isBlockAtPosition(position + Vector3.up, 1, ~Ignore))
  560. return;
  561. //If block at Position is walkable set it to moveTo
  562. if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore))
  563. {
  564. moveTo = hit;
  565. _currentBlock = moveTo;
  566. StartCoroutine(MoveCoroutine(_currentBlock, transform, speed, 0.3f));
  567. }
  568. //else if block down one is walkable
  569. else if (Block.isBlockAtPosition(position + Vector3.down, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore))
  570. {
  571. moveTo = hit;
  572. _currentBlock = moveTo;
  573. StartCoroutine(MoveDownCoroutine(_currentBlock, transform, speed, 0.3f));
  574. }
  575. }
  576. public void conveyorMoveForward(Direction direction, float speed)
  577. {
  578. Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted
  579. Block hit; //output of block detection
  580. Block moveTo = _currentBlock; //block we'll actually move to
  581. if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore))
  582. {
  583. moveTo = hit;
  584. _currentBlock = moveTo;
  585. StartCoroutine(MoveConveyorForwardCoroutine(_currentBlock, transform, speed, 0.3f));
  586. }
  587. }
  588. public void conveyorMoveBackward(Direction direction, float speed)
  589. {
  590. Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted
  591. Block hit; //output of block detection
  592. Block moveTo = _currentBlock; //block we'll actually move to
  593. if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore))
  594. {
  595. moveTo = hit;
  596. _currentBlock = moveTo;
  597. StartCoroutine(MoveConveyorBackwardCoroutine(_currentBlock, transform, speed, 0.3f));
  598. }
  599. }
  600. public void conveyorMoveLeft(Direction direction, float speed)
  601. {
  602. Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted
  603. Block hit; //output of block detection
  604. Block moveTo = _currentBlock; //block we'll actually move to
  605. if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore))
  606. {
  607. moveTo = hit;
  608. _currentBlock = moveTo;
  609. StartCoroutine(MoveConveyorLeftCoroutine(_currentBlock, transform, speed, 0.3f));
  610. }
  611. }
  612. public void conveyorMoveRight(Direction direction, float speed)
  613. {
  614. Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted
  615. Block hit; //output of block detection
  616. Block moveTo = _currentBlock; //block we'll actually move to
  617. if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore))
  618. {
  619. moveTo = hit;
  620. _currentBlock = moveTo;
  621. StartCoroutine(MoveConveyorRightCoroutine(_currentBlock, transform, speed, 0.3f));
  622. }
  623. }
  624. public void CannonRMove(float speed)
  625. {
  626. Direction direction = Direction.Right;
  627. Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted
  628. Block hit; //output of block detection
  629. Block moveTo = _currentBlock; //block we'll actually move to
  630. if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore))
  631. {
  632. moveTo = hit;
  633. _currentBlock = moveTo;
  634. StartCoroutine(PushRightCoroutine(transform, speed));
  635. }
  636. }
  637. public void CannonLMove(float speed)
  638. {
  639. Direction direction = Direction.Left;
  640. Vector3 position = _currentBlock.position + direction.ToVector(transform); // position wanted
  641. Block hit; //output of block detection
  642. Block moveTo = _currentBlock; //block we'll actually move to
  643. if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore))
  644. {
  645. moveTo = hit;
  646. _currentBlock = moveTo;
  647. StartCoroutine(PushLeftCoroutine(transform, speed));
  648. }
  649. }
  650. #endregion Depricated
  651. }