-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Has collision detection and gravity and everything.
- Loading branch information
1 parent
abb8cfc
commit 436a4de
Showing
14 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.