Description:
Power Transmission is a game me and my team made for the Global Game Jam 2018. We made this at the location of Hogeschool van Amsterdam.
It’s co-op game in which you have to share your abilities with a fellow player to solve the puzzles and progress to the next level. The game can be played on PC or Mac with two Xbox controllers.
I worked mainly on gameplay, audio integration and UI.
Started: January 2018
Finished: March 2018
code:
This is a class I wrote for the movement of the player. It’s a 2D platformer, so all movement and physics are in 2D.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
public class PlayerMovement : MonoBehaviour { // Editable in inspector public float speed = 3.5f; public float jumpForce = 8.0f; // Declare in inspector public Transform groundCheck; public LayerMask whatIsGround; private Rigidbody2D rigidBody2D; private bool grounded = true; private float groundRadius = 0.2f; private float gravityScale; private float moveVertical; private float moveHorizontal; private float tempMove; private bool climbable = false; private bool facingRight = false; private void Start() { rigidBody2D = GetComponent<Rigidbody2D>(); gravityScale = rigidBody2D.gravityScale; groundCheck = transform.GetChild(0); } private void FixedUpdate() { // Check if player touches a ground object grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround); CheckHorizontalInput(); CheckVerticalInput(); CheckJumpInput(); } // Check horizontal input, then move if player is grounded or turn mid-jump. private void CheckHorizontalInput() { moveHorizontal = (Input.GetAxis("Horizontal")); if (grounded) { rigidBody2D.velocity = new Vector2(moveHorizontal * speed, rigidBody2D.velocity.y); } } // Check vertical input and if player is in front of a climbable object, then move player up or down. private void CheckVerticalInput() { moveVertical = (Input.GetAxis("Vertical")); if (climbable) { rigidBody2D.velocity = new Vector2(moveHorizontal * speed, moveVertical * speed); } } // Check if jump button is pressed and if player is grounded, then apply force to the player's velocity. private void CheckJumpInput() { if (grounded && (Input.GetAxis("A_Button") >= 0.01)) { rigidBody2D.velocity = new Vector2(rigidBody2D.velocity.x, jumpForce); tempMove = moveHorizontal; } else if (!grounded) { // If player turns mid-jump if (tempMove > 0.01 && moveHorizontal < -0.01) { rigidBody2D.velocity = new Vector2(moveHorizontal * speed * 0.3f, rigidBody2D.velocity.y); } else if (tempMove < -0.01 && moveHorizontal > 0.01) { rigidBody2D.velocity = new Vector2(moveHorizontal * speed * 0.3f, rigidBody2D.velocity.y); } } } private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Stairs") { climbable = true; rigidBody2D.gravityScale = 0; } } private void OnTriggerExit2D(Collider2D collision) { if (collision.tag == "Stairs") { climbable = false; rigidBody2D.gravityScale = gravityScale; } } } |