Advertisement
Guest User

Platformer Fixes

a guest
May 19th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. In player_character_controller.cs:
  2.  
  3. Near top added SerializeField above mask variable:
  4.  
  5. [SerializeField]
  6. private LayerMask mask;
  7.  
  8.  
  9. In FixedUpdate for Collision/Check Ground:
  10. Added mask to end of Physics2D.Linecast:
  11. RaycastHit2D cast = Physics2D.Linecast(new Vector2(transform.position.x, boxCollider.bounds.min.y), new Vector2(transform.position.x, boxCollider.bounds.min.y + deltaV), mask);
  12.  
  13.  
  14. Added this function:
  15. public bool IsGrounded()
  16. {
  17. RaycastHit2D cast = Physics2D.Linecast(new Vector2(transform.position.x, boxCollider.bounds.min.y), new Vector2(transform.position.x, boxCollider.bounds.min.y + gravity), mask);
  18. if (cast.collider != null)
  19. {
  20. return true;
  21. }
  22.  
  23. return false;
  24. }
  25.  
  26. ==============================================
  27.  
  28. In bullet_move.cs:
  29. Changed OnTriggerEnter2D function to OnCollisionEnter2D:
  30. private void OnCollisionEnter2D(Collision2D collision)
  31. {
  32. if (collision.collider.tag != "Player")
  33. {
  34. Destroy(gameObject);
  35. }
  36. }
  37.  
  38. ==============================================
  39.  
  40. In movingplatform.cs:
  41. Added these functions:
  42.  
  43. private void OnCollisionEnter2D(Collision2D collision)
  44. {
  45. if (collision.gameObject.tag == "Player")
  46. {
  47. player_character_controller pc = collision.gameObject.GetComponent<player_character_controller>();
  48. if (pc.IsGrounded())
  49. {
  50. collision.gameObject.transform.SetParent(transform);
  51. }
  52. }
  53. }
  54.  
  55. private void OnCollisionExit2D(Collision2D collision)
  56. {
  57. if (collision.gameObject.tag == "Player")
  58. {
  59. collision.gameObject.transform.SetParent(null);
  60. }
  61. }
  62.  
  63. ==============================================
  64.  
  65. In Scene:
  66. Changed grounds, bench, sign, boat objects to use "grounds" Layer
  67. on Player gameObject for Player_character_controller component set Mask to "grounds"
  68. Horizontal Velocity and Vertical Velocity needed to be increased (I set it to 5 and 10 respectively)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement