fixed merge

This commit is contained in:
2020-02-01 01:47:44 -05:00
parent 6902571489
commit 3c794540ce
8 changed files with 200 additions and 8 deletions

View File

@@ -7,18 +7,22 @@ public class Player : MonoBehaviour
[SerializeField] private float runSpeed = 10f;
[SerializeField] private float jumpSpeed = 10f;
[SerializeField] private float runFasterFactor = 1.5f;
[SerializeField] private float groundErrorThreshold = 0.01f;
private Rigidbody2D rigidbody;
private PolygonCollider2D collider;
private bool isInEncounter = false;
private void Start()
{
rigidbody = GetComponent<Rigidbody2D>();
collider = GetComponent<PolygonCollider2D>();
}
private void Update()
{
Debug.Log(HasEncounteredEnemy());
//isInEncounter = HasEncounteredEnemy();
//if (isInEncounter)
MovePlayer();
}
@@ -30,10 +34,8 @@ public class Player : MonoBehaviour
private void Jump()
{
var playerOnGround = rigidbody.IsTouchingLayers(LayerMask.GetMask(LayerNames.Ground));
// Jump
if (Input.GetKey(KeyCode.Space) && playerOnGround)
if (Input.GetKey(KeyCode.Space) && IsPlayerOnGround())
{
rigidbody.velocity += new Vector2(0, jumpSpeed);
rigidbody.velocity = new Vector2(rigidbody.velocity.x,
@@ -62,6 +64,16 @@ public class Player : MonoBehaviour
}
}
private bool IsPlayerOnGround()
{
RaycastHit2D hit = Physics2D.Raycast(transform.position,
-Vector2.up,
1f + groundErrorThreshold,
LayerMask.GetMask(LayerNames.Ground));
return hit.collider != null && hit.collider.IsTouching(collider);
}
private bool HasEncounteredEnemy()
{
return rigidbody.IsTouchingLayers(LayerMask.GetMask(LayerNames.Enemies));