Skip to content

Commit

Permalink
Added basic platformer movements.
Browse files Browse the repository at this point in the history
Has collision detection and gravity and everything.
  • Loading branch information
lahlidahlia committed Nov 17, 2015
1 parent abb8cfc commit 436a4de
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 0 deletions.
Binary file added Assets/NoFriction.physicsMaterial2D
Binary file not shown.
8 changes: 8 additions & 0 deletions Assets/NoFriction.physicsMaterial2D.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Prefabs/Platform.prefab
Binary file not shown.
8 changes: 8 additions & 0 deletions Assets/Prefabs/Platform.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Prefabs/Player.prefab
Binary file not shown.
8 changes: 8 additions & 0 deletions Assets/Prefabs/Player.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Assets/Scenes/test.unity
Binary file not shown.
35 changes: 35 additions & 0 deletions Assets/Scripts/PlayerScript.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using UnityEngine;
using System.Collections;

public class PlayerScript : MonoBehaviour {
public float speed;
public float jumpStrength;
public Transform groundChecker; // A point on the player, used to check for ground.
public LayerMask groundLayerMask; // Only check for ground using ground, and nothing else.

private float groundCheckerRadius; // How large of a circle the checker is.
private bool grounded; // Whether the player is on the ground, for jump checking.
private Rigidbody2D rigidbody2D;


void Start () {
// Get the player's rigidbody2D component for movement uses.
rigidbody2D = GetComponent<Rigidbody2D>();
groundCheckerRadius = GetComponent<CircleCollider2D>().radius;
print(groundCheckerRadius);
}


// Update is called once per frame.
void Update () {
// Make player move left or right, depending on which key is pressed.
rigidbody2D.velocity = new Vector2(Input.GetAxisRaw("Horizontal") * speed, rigidbody2D.velocity.y);

grounded = Physics2D.OverlapCircle(groundChecker.position, groundCheckerRadius, groundLayerMask);
print(grounded);
if (grounded && Input.GetButton("Jump")) {
rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, jumpStrength);
grounded = false;
}
}
}
12 changes: 12 additions & 0 deletions Assets/Scripts/PlayerScript.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Assets/Sprites/Platform.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Sprites/Player.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions Assets/Sprites/Player.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified ProjectSettings/InputManager.asset
Binary file not shown.
Binary file modified ProjectSettings/TagManager.asset
Binary file not shown.

0 comments on commit 436a4de

Please sign in to comment.