Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- In player_character_controller.cs:
- Near top added SerializeField above mask variable:
- [SerializeField]
- private LayerMask mask;
- In FixedUpdate for Collision/Check Ground:
- Added mask to end of Physics2D.Linecast:
- RaycastHit2D cast = Physics2D.Linecast(new Vector2(transform.position.x, boxCollider.bounds.min.y), new Vector2(transform.position.x, boxCollider.bounds.min.y + deltaV), mask);
- Added this function:
- public bool IsGrounded()
- {
- RaycastHit2D cast = Physics2D.Linecast(new Vector2(transform.position.x, boxCollider.bounds.min.y), new Vector2(transform.position.x, boxCollider.bounds.min.y + gravity), mask);
- if (cast.collider != null)
- {
- return true;
- }
- return false;
- }
- ==============================================
- In bullet_move.cs:
- Changed OnTriggerEnter2D function to OnCollisionEnter2D:
- private void OnCollisionEnter2D(Collision2D collision)
- {
- if (collision.collider.tag != "Player")
- {
- Destroy(gameObject);
- }
- }
- ==============================================
- In movingplatform.cs:
- Added these functions:
- private void OnCollisionEnter2D(Collision2D collision)
- {
- if (collision.gameObject.tag == "Player")
- {
- player_character_controller pc = collision.gameObject.GetComponent<player_character_controller>();
- if (pc.IsGrounded())
- {
- collision.gameObject.transform.SetParent(transform);
- }
- }
- }
- private void OnCollisionExit2D(Collision2D collision)
- {
- if (collision.gameObject.tag == "Player")
- {
- collision.gameObject.transform.SetParent(null);
- }
- }
- ==============================================
- In Scene:
- Changed grounds, bench, sign, boat objects to use "grounds" Layer
- on Player gameObject for Player_character_controller component set Mask to "grounds"
- 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